blob: 2f6b6f20d7ec7a80f930a629fcb010102a8eeb66 [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 Marchetti79ecf482017-06-22 17:21:44 -040013 git url: "https://osm.etsi.org/gerrit/${env.GERRIT_PROJECT}"
Mike Marchetti52de9722017-06-22 15:18:23 -040014
Mike Marchetti79ecf482017-06-22 17:21:44 -040015 sh "git fetch origin ${env.GERRIT_REFSPEC}"
16 if (env.GERRIT_PATCHSET_REVISION.size() > 0 ) {
17 sh "git checkout -f ${env.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 Marchetti79ecf482017-06-22 17:21:44 -040028 mdg = Get_MDG("${env.GERRIT_PROJECT}")
Mike Marchetti52de9722017-06-22 15:18:23 -040029 println("MDG is ${mdg}")
30
Mike Marchetti79ecf482017-06-22 17:21:44 -040031 if ( env.GERRIT_EVENT_TYPE.equals('change-merged') ) {
32 def downstream_params = [
33 string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH),
34 string(name: 'GERRIT_PROJECT', value: env.GERRIT_PROJECT),
35 string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC),
36 string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION),
37 ]
38 result = build job: "${mdg}/${env.GERRIT_BRANCH}", parameters: downstream_params, propagate: true
39 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
55 container_name = "${env.GERRIT_PROJECT}-${env.GERRIT_BRANCH}"
56
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}