updates to jenkins
[test.git] / Jenkinsfile
index e30c94b..fd340d9 100644 (file)
@@ -1,3 +1,13 @@
+properties([
+    parameters([
+        string(defaultValue: env.GERRIT_BRANCH, description: '', name: 'GERRIT_BRANCH'),
+        string(defaultValue: env.GERRIT_PROJECT, description: '', name: 'GERRIT_PROJECT'),
+        string(defaultValue: env.GERRIT_REFSPEC, description: '', name: 'GERRIT_REFSPEC'),
+        string(defaultValue: env.GERRIT_PATCHSET_REVISION, description: '', name: 'GERRIT_PATCHSET_REVISION'),
+    ])
+])
+
+
 def Get_MDG(project) {
     // split the project.
     def values = project.split('/')
@@ -25,40 +35,58 @@ def devops_checkout() {
 }
 
 node {
-    stage('Prepare') {
-        sh 'env'
-        devops_checkout()
-    }
-
-    stage('Checkout') {
-        project_checkout()
-    }
-
-    container_name = "${GERRIT_PROJECT}-${GERRIT_BRANCH}"
-
     mdg = Get_MDG("${GERRIT_PROJECT}")
     println("MDG is ${mdg}")
 
-    stage('Docker-Build') {
-        sh "docker build -t ${container_name} ."
+    if ( env.GERRIT_EVENT_TYPE != null ) {
+        // pipeline running from gerrit trigger.
+        // kickoff the downstream multibranch pipeline
+        def downstream_params = [
+            string(name: 'GERRIT_BRANCH', value: GERRIT_BRANCH),
+            string(name: 'GERRIT_PROJECT', value: GERRIT_PROJECT),
+            string(name: 'GERRIT_REFSPEC', value: GERRIT_REFSPEC),
+            string(name: 'GERRIT_PATCHSET_REVISION', value: GERRIT_PATCHSET_REVISION),
+        ]
+        result = build job: "${mdg}/${GERRIT_BRANCH}", parameters: downstream_params, propagate: true
+        if (result.getResult() != 'SUCCESS') {
+            project = result.getProjectName()
+            build = result.getNumber()
+            error("${project} build ${build} failed")
+        }
     }
-
-    withDockerContainer("${container_name}") {
-        stage('Docker-Setup') {
-            sh '''
-               groupadd -o -g $(id -g) -r jenkins
-               useradd -o -u $(id -u) --create-home -r -g  jenkins jenkins
-               '''
+    else {
+        stage('Prepare') {
+            sh 'env'
+            devops_checkout()
         }
-        stage('Test') {
-            sh 'devops-stages/stage-test.sh'
+
+        stage('Checkout') {
+            project_checkout()
         }
-        stage('Build') {
-            sh 'devops-stages/stage-build.sh'
+
+        container_name = "${GERRIT_PROJECT}-${GERRIT_BRANCH}"
+
+        stage('Docker-Build') {
+            sh "docker build -t ${container_name} ."
         }
-        stage('Archive') {
-            sh 'devops-stages/stage-archive.sh'
-            archiveArtifacts artifacts: "dists/**,pool/${mdg}/*.deb", fingerprint: true
+
+        withDockerContainer("${container_name}") {
+            stage('Docker-Setup') {
+                sh '''
+                   groupadd -o -g $(id -g) -r jenkins
+                   useradd -o -u $(id -u) --create-home -r -g  jenkins jenkins
+                   '''
+            }
+            stage('Test') {
+                sh 'devops-stages/stage-test.sh'
+            }
+            stage('Build') {
+                sh 'devops-stages/stage-build.sh'
+            }
+            stage('Archive') {
+                sh 'devops-stages/stage-archive.sh'
+                archiveArtifacts artifacts: "dists/**,pool/${mdg}/*.deb", fingerprint: true
+            }
         }
-    }
+     }
 }