Bug 1409
[osm/devops.git] / jenkins / ci-pipelines / ci_stage_2.groovy
index 18de85f..aa9c906 100644 (file)
@@ -20,6 +20,7 @@ def project_checkout(url_prefix,project,refspec,revision) {
     // this is done automaticaly by the multibranch pipeline plugin
     // git url: "${url_prefix}/${project}"
 
+    sh "git fetch --tags"
     sh "git fetch origin ${refspec}"
     if (GERRIT_PATCHSET_REVISION.size() > 0 ) {
         sh "git checkout -f ${revision}"
@@ -41,9 +42,9 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
     stage('License Scan') {
       if (!JOB_NAME.contains('merge')) {
         sh "devops/tools/license_scan.sh"
-      } 
+      }
       else {
-        Println("skip the scan for merge")
+        println("skip the scan for merge")
       }
     }
 
@@ -78,6 +79,32 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
         }
     }
 
+    if (fileExists('snap/snapcraft.yaml')) {
+        stage('Snap build') {
+            sh "docker pull snapcore/snapcraft:stable"
+            sh "sudo rm -rf ${WORKSPACE}/stage/ ${WORKSPACE}/parts/ ${WORKSPACE}/prime/ ${WORKSPACE}/*.snap"
+            sh "snapcraft --use-lxd"
+            sh "mv ${WORKSPACE}/${mdg}_*.snap ${WORKSPACE}/${mdg}.snap"
+            sh "sudo rm -rf ${WORKSPACE}/stage/ ${WORKSPACE}/parts/ ${WORKSPACE}/prime/"
+
+            REV=""
+            if ( !JOB_NAME.contains('merge') ) {
+                REV="/"+"${GERRIT_REFSPEC}".replaceAll('/','-')
+            }
+            channel="latest"
+            if (BRANCH_NAME.startsWith("v")) {
+                channel=BRANCH_NAME.substring(1)
+            } else if (BRANCH_NAME!="master") {
+                REV="/"+BRANCH_NAME+REV.replaceAll('/','-')
+            }
+
+            sh "sudo docker run -v ~/.snapcraft:/snapcraft -v ${WORKSPACE}:/build " +
+                "-w /build snapcore/snapcraft:stable /bin/bash -c " +
+                "\"snapcraft login --with /snapcraft/config ; snapcraft push --release=${channel}/edge${REV} ${mdg}.snap\""
+            sh "sudo rm -rf ${WORKSPACE}/*.snap"
+        }
+    }
+
     if ( do_stage_3 ) {
 
         stage('Build System') {