blob: 86e051416152543d882fc4ed9fbda3596e8f9d61 [file] [log] [blame]
Mike Marchetti52de9722017-06-22 15:18:23 -04001def Get_MDG(project) {
2 // split the project.
3 def values = project.split('/')
4 if ( values.size() > 1 ) {
5 return values[1]
6 }
7 // no prefix, likely just the project name then
8 return project
9}
10
11def project_checkout() {
12 // checkout the project
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040013 git url: "https://osm.etsi.org/gerrit/${GERRIT_PROJECT}"
Mike Marchetti52de9722017-06-22 15:18:23 -040014
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040015 sh "git fetch origin ${GERRIT_REFSPEC}"
16 if (GERRIT_PATCHSET_REVISION.size() > 0 ) {
17 sh "git checkout -f ${GERRIT_PATCHSET_REVISION}"
Mike Marchetti52de9722017-06-22 15:18:23 -040018 }
19}
20
21def devops_checkout() {
22 dir('devops') {
23 git url: 'https://osm.etsi.org/gerrit/osm/devops'
24 }
25}
26
27node {
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040028 mdg = Get_MDG("${GERRIT_PROJECT}")
Mike Marchetti52de9722017-06-22 15:18:23 -040029 println("MDG is ${mdg}")
30
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040031 if ( GERRIT_EVENT_TYPE.equals('change-merged') ) {
Mike Marchetti79ecf482017-06-22 17:21:44 -040032 def downstream_params = [
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040033 string(name: 'GERRIT_BRANCH', value: GERRIT_BRANCH),
34 string(name: 'GERRIT_PROJECT', value: GERRIT_PROJECT),
35 string(name: 'GERRIT_REFSPEC', value: GERRIT_REFSPEC),
36 string(name: 'GERRIT_PATCHSET_REVISION', value: GERRIT_PATCHSET_REVISION),
Mike Marchetti79ecf482017-06-22 17:21:44 -040037 ]
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040038 result = build job: "${mdg}/${GERRIT_BRANCH}", parameters: downstream_params, propagate: true
Mike Marchetti79ecf482017-06-22 17:21:44 -040039 if (result.getResult() != 'SUCCESS') {
40 project = result.getProjectName()
41 build = result.getNumber()
42 error("${project} build ${build} failed")
43 }
Mike Marchetti52de9722017-06-22 15:18:23 -040044 }
Mike Marchetti79ecf482017-06-22 17:21:44 -040045 else {
46 stage('Prepare') {
47 sh 'env'
48 devops_checkout()
49 }
Mike Marchetti52de9722017-06-22 15:18:23 -040050
Mike Marchetti79ecf482017-06-22 17:21:44 -040051 stage('Checkout') {
52 project_checkout()
Mike Marchetti52de9722017-06-22 15:18:23 -040053 }
Mike Marchetti79ecf482017-06-22 17:21:44 -040054
Mike Marchetti66e1c2b2017-06-22 17:41:38 -040055 container_name = "${GERRIT_PROJECT}-${GERRIT_BRANCH}"
Mike Marchetti79ecf482017-06-22 17:21:44 -040056
57
58 stage('Docker-Build') {
59 sh "docker build -t ${container_name} ."
Mike Marchetti52de9722017-06-22 15:18:23 -040060 }
Mike Marchetti79ecf482017-06-22 17:21:44 -040061
62 withDockerContainer("${container_name}") {
63 stage('Docker-Setup') {
64 sh '''
65 groupadd -o -g $(id -g) -r jenkins
66 useradd -o -u $(id -u) --create-home -r -g jenkins jenkins
67 '''
68 }
69 stage('Test') {
70 sh 'devops-stages/stage-test.sh'
71 }
72 stage('Build') {
73 sh 'devops-stages/stage-build.sh'
74 }
75 stage('Archive') {
76 sh 'devops-stages/stage-archive.sh'
77 archiveArtifacts artifacts: "dists/**,pool/${mdg}/*.deb", fingerprint: true
78 }
Mike Marchetti52de9722017-06-22 15:18:23 -040079 }
Mike Marchetti79ecf482017-06-22 17:21:44 -040080 }
Mike Marchetti30b8eb72017-06-22 09:15:03 -040081}