blob: fd340d9b73fdc5549b780d82e92abb087f4e4ef0 [file] [log] [blame]
Mike Marchetti2cc51442017-06-23 10:24:22 -04001properties([
2 parameters([
3 string(defaultValue: env.GERRIT_BRANCH, description: '', name: 'GERRIT_BRANCH'),
Mike Marchetti420ea432017-06-23 10:55:52 -04004 string(defaultValue: env.GERRIT_PROJECT, description: '', name: 'GERRIT_PROJECT'),
Mike Marchetti2cc51442017-06-23 10:24:22 -04005 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 Marchetti37efaf82017-06-23 11:26:16 -040010
Mike Marchetti52de9722017-06-22 15:18:23 -040011def Get_MDG(project) {
12 // split the project.
13 def values = project.split('/')
14 if ( values.size() > 1 ) {
15 return values[1]
16 }
17 // no prefix, likely just the project name then
18 return project
19}
20
21def project_checkout() {
22 // checkout the project
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040023 git url: "https://osm.etsi.org/gerrit/${GERRIT_PROJECT}"
Mike Marchetti52de9722017-06-22 15:18:23 -040024
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040025 sh "git fetch origin ${GERRIT_REFSPEC}"
26 if (GERRIT_PATCHSET_REVISION.size() > 0 ) {
27 sh "git checkout -f ${GERRIT_PATCHSET_REVISION}"
Mike Marchetti52de9722017-06-22 15:18:23 -040028 }
29}
30
31def devops_checkout() {
32 dir('devops') {
33 git url: 'https://osm.etsi.org/gerrit/osm/devops'
34 }
35}
36
37node {
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040038 mdg = Get_MDG("${GERRIT_PROJECT}")
Mike Marchetti52de9722017-06-22 15:18:23 -040039 println("MDG is ${mdg}")
40
Mike Marchetti2cc51442017-06-23 10:24:22 -040041 if ( env.GERRIT_EVENT_TYPE != null ) {
42 // pipeline running from gerrit trigger.
43 // kickoff the downstream multibranch pipeline
Mike Marchetti79ecf482017-06-22 17:21:44 -040044 def downstream_params = [
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040045 string(name: 'GERRIT_BRANCH', value: GERRIT_BRANCH),
46 string(name: 'GERRIT_PROJECT', value: GERRIT_PROJECT),
47 string(name: 'GERRIT_REFSPEC', value: GERRIT_REFSPEC),
48 string(name: 'GERRIT_PATCHSET_REVISION', value: GERRIT_PATCHSET_REVISION),
Mike Marchetti79ecf482017-06-22 17:21:44 -040049 ]
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040050 result = build job: "${mdg}/${GERRIT_BRANCH}", parameters: downstream_params, propagate: true
Mike Marchetti79ecf482017-06-22 17:21:44 -040051 if (result.getResult() != 'SUCCESS') {
52 project = result.getProjectName()
53 build = result.getNumber()
54 error("${project} build ${build} failed")
55 }
Mike Marchetti52de9722017-06-22 15:18:23 -040056 }
Mike Marchetti79ecf482017-06-22 17:21:44 -040057 else {
58 stage('Prepare') {
59 sh 'env'
60 devops_checkout()
61 }
Mike Marchetti52de9722017-06-22 15:18:23 -040062
Mike Marchetti79ecf482017-06-22 17:21:44 -040063 stage('Checkout') {
64 project_checkout()
Mike Marchetti52de9722017-06-22 15:18:23 -040065 }
Mike Marchetti79ecf482017-06-22 17:21:44 -040066
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040067 container_name = "${GERRIT_PROJECT}-${GERRIT_BRANCH}"
Mike Marchetti79ecf482017-06-22 17:21:44 -040068
Mike Marchetti79ecf482017-06-22 17:21:44 -040069 stage('Docker-Build') {
70 sh "docker build -t ${container_name} ."
Mike Marchetti52de9722017-06-22 15:18:23 -040071 }
Mike Marchetti79ecf482017-06-22 17:21:44 -040072
73 withDockerContainer("${container_name}") {
74 stage('Docker-Setup') {
75 sh '''
76 groupadd -o -g $(id -g) -r jenkins
77 useradd -o -u $(id -u) --create-home -r -g jenkins jenkins
78 '''
79 }
80 stage('Test') {
81 sh 'devops-stages/stage-test.sh'
82 }
83 stage('Build') {
84 sh 'devops-stages/stage-build.sh'
85 }
86 stage('Archive') {
87 sh 'devops-stages/stage-archive.sh'
88 archiveArtifacts artifacts: "dists/**,pool/${mdg}/*.deb", fingerprint: true
89 }
Mike Marchetti52de9722017-06-22 15:18:23 -040090 }
Mike Marchetti79ecf482017-06-22 17:21:44 -040091 }
Mike Marchetti30b8eb72017-06-22 09:15:03 -040092}