| Mike Marchetti | 2cc5144 | 2017-06-23 10:24:22 -0400 | [diff] [blame^] | 1 | properties([ |
| 2 | parameters([ |
| 3 | string(defaultValue: env.GERRIT_BRANCH, description: '', name: 'GERRIT_BRANCH'), |
| 4 | string(defaultValue: env.GERRIT_PROJEC, description: '', name: 'GERRIT_PROJECT'), |
| 5 | string(defaultValue: env.GERRIT_REFSPEC, description: '', name: 'GERRIT_REFSPEC'), |
| 6 | string(defaultValue: env.GERRIT_PATCHSET_REVISION, description: '', name: 'GERRIT_PATCHSET_REVISION'), |
| 7 | ]) |
| 8 | ]) |
| 9 | |
| Mike Marchetti | 52de972 | 2017-06-22 15:18:23 -0400 | [diff] [blame] | 10 | def Get_MDG(project) { |
| 11 | // split the project. |
| 12 | def values = project.split('/') |
| 13 | if ( values.size() > 1 ) { |
| 14 | return values[1] |
| 15 | } |
| 16 | // no prefix, likely just the project name then |
| 17 | return project |
| 18 | } |
| 19 | |
| 20 | def project_checkout() { |
| 21 | // checkout the project |
| Mike Marchetti | 66e1c2b | 2017-06-22 17:41:38 -0400 | [diff] [blame] | 22 | git url: "https://osm.etsi.org/gerrit/${GERRIT_PROJECT}" |
| Mike Marchetti | 52de972 | 2017-06-22 15:18:23 -0400 | [diff] [blame] | 23 | |
| Mike Marchetti | 66e1c2b | 2017-06-22 17:41:38 -0400 | [diff] [blame] | 24 | sh "git fetch origin ${GERRIT_REFSPEC}" |
| 25 | if (GERRIT_PATCHSET_REVISION.size() > 0 ) { |
| 26 | sh "git checkout -f ${GERRIT_PATCHSET_REVISION}" |
| Mike Marchetti | 52de972 | 2017-06-22 15:18:23 -0400 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | |
| 30 | def devops_checkout() { |
| 31 | dir('devops') { |
| 32 | git url: 'https://osm.etsi.org/gerrit/osm/devops' |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | node { |
| Mike Marchetti | 66e1c2b | 2017-06-22 17:41:38 -0400 | [diff] [blame] | 37 | mdg = Get_MDG("${GERRIT_PROJECT}") |
| Mike Marchetti | 52de972 | 2017-06-22 15:18:23 -0400 | [diff] [blame] | 38 | println("MDG is ${mdg}") |
| 39 | |
| Mike Marchetti | 2cc5144 | 2017-06-23 10:24:22 -0400 | [diff] [blame^] | 40 | if ( env.GERRIT_EVENT_TYPE != null ) { |
| 41 | // pipeline running from gerrit trigger. |
| 42 | // kickoff the downstream multibranch pipeline |
| Mike Marchetti | 79ecf48 | 2017-06-22 17:21:44 -0400 | [diff] [blame] | 43 | def downstream_params = [ |
| Mike Marchetti | 66e1c2b | 2017-06-22 17:41:38 -0400 | [diff] [blame] | 44 | string(name: 'GERRIT_BRANCH', value: GERRIT_BRANCH), |
| 45 | string(name: 'GERRIT_PROJECT', value: GERRIT_PROJECT), |
| 46 | string(name: 'GERRIT_REFSPEC', value: GERRIT_REFSPEC), |
| 47 | string(name: 'GERRIT_PATCHSET_REVISION', value: GERRIT_PATCHSET_REVISION), |
| Mike Marchetti | 79ecf48 | 2017-06-22 17:21:44 -0400 | [diff] [blame] | 48 | ] |
| Mike Marchetti | 66e1c2b | 2017-06-22 17:41:38 -0400 | [diff] [blame] | 49 | result = build job: "${mdg}/${GERRIT_BRANCH}", parameters: downstream_params, propagate: true |
| Mike Marchetti | 79ecf48 | 2017-06-22 17:21:44 -0400 | [diff] [blame] | 50 | if (result.getResult() != 'SUCCESS') { |
| 51 | project = result.getProjectName() |
| 52 | build = result.getNumber() |
| 53 | error("${project} build ${build} failed") |
| 54 | } |
| Mike Marchetti | 52de972 | 2017-06-22 15:18:23 -0400 | [diff] [blame] | 55 | } |
| Mike Marchetti | 79ecf48 | 2017-06-22 17:21:44 -0400 | [diff] [blame] | 56 | else { |
| 57 | stage('Prepare') { |
| 58 | sh 'env' |
| 59 | devops_checkout() |
| 60 | } |
| Mike Marchetti | 52de972 | 2017-06-22 15:18:23 -0400 | [diff] [blame] | 61 | |
| Mike Marchetti | 79ecf48 | 2017-06-22 17:21:44 -0400 | [diff] [blame] | 62 | stage('Checkout') { |
| 63 | project_checkout() |
| Mike Marchetti | 52de972 | 2017-06-22 15:18:23 -0400 | [diff] [blame] | 64 | } |
| Mike Marchetti | 79ecf48 | 2017-06-22 17:21:44 -0400 | [diff] [blame] | 65 | |
| Mike Marchetti | 66e1c2b | 2017-06-22 17:41:38 -0400 | [diff] [blame] | 66 | container_name = "${GERRIT_PROJECT}-${GERRIT_BRANCH}" |
| Mike Marchetti | 79ecf48 | 2017-06-22 17:21:44 -0400 | [diff] [blame] | 67 | |
| Mike Marchetti | 79ecf48 | 2017-06-22 17:21:44 -0400 | [diff] [blame] | 68 | stage('Docker-Build') { |
| 69 | sh "docker build -t ${container_name} ." |
| Mike Marchetti | 52de972 | 2017-06-22 15:18:23 -0400 | [diff] [blame] | 70 | } |
| Mike Marchetti | 79ecf48 | 2017-06-22 17:21:44 -0400 | [diff] [blame] | 71 | |
| 72 | withDockerContainer("${container_name}") { |
| 73 | stage('Docker-Setup') { |
| 74 | sh ''' |
| 75 | groupadd -o -g $(id -g) -r jenkins |
| 76 | useradd -o -u $(id -u) --create-home -r -g jenkins jenkins |
| 77 | ''' |
| 78 | } |
| 79 | stage('Test') { |
| 80 | sh 'devops-stages/stage-test.sh' |
| 81 | } |
| 82 | stage('Build') { |
| 83 | sh 'devops-stages/stage-build.sh' |
| 84 | } |
| 85 | stage('Archive') { |
| 86 | sh 'devops-stages/stage-archive.sh' |
| 87 | archiveArtifacts artifacts: "dists/**,pool/${mdg}/*.deb", fingerprint: true |
| 88 | } |
| Mike Marchetti | 52de972 | 2017-06-22 15:18:23 -0400 | [diff] [blame] | 89 | } |
| Mike Marchetti | 79ecf48 | 2017-06-22 17:21:44 -0400 | [diff] [blame] | 90 | } |
| Mike Marchetti | 30b8eb7 | 2017-06-22 09:15:03 -0400 | [diff] [blame] | 91 | } |