Force charm build on merge 38/12538/2
authorMark Beierl <mark.beierl@canonical.com>
Thu, 8 Sep 2022 15:56:24 +0000 (11:56 -0400)
committerbeierlm <mark.beierl@canonical.com>
Thu, 8 Sep 2022 17:13:22 +0000 (19:13 +0200)
There is no easy method post-merge to determine what
charms need to be rebuilt, so we will rebuild all of
them

Change-Id: I50436a63cf3f63e32105051df8c571dd2dd6d2dd
Signed-off-by: Mark Beierl <mark.beierl@canonical.com>
jenkins/ci-pipelines/ci_stage_2.groovy

index 1c8911f..73842e3 100644 (file)
@@ -31,6 +31,7 @@ def project_checkout(url_prefix,project,refspec,revision) {
 def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifactory_server,docker_args="",do_stage_4=false) {
     println("do_stage_3= ${do_stage_3}")
     ci_helper = load "devops/jenkins/ci-pipelines/ci_helper.groovy"
+    def isMergeJob = JOB_NAME.contains('merge')
 
     stage('Prepare') {
         sh 'env'
@@ -41,7 +42,7 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
     }
 
     stage('License Scan') {
-      if (!JOB_NAME.contains('merge')) {
+      if (!isMergeJob) {
         sh "devops/tools/license_scan.sh"
       }
       else {
@@ -51,7 +52,7 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
 
     stage('Release Note Check') {
       if (fileExists('devops-stages/stage-releasenote.sh')) {
-        if (!JOB_NAME.contains('merge')) {
+        if (!sMergeJob) {
             sh "devops-stages/stage-releasenote.sh"
         }
         else {
@@ -109,7 +110,7 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
                 sh "sudo rm -rf ${WORKSPACE}/stage/ ${WORKSPACE}/parts/ ${WORKSPACE}/prime/"
 
                 REV=""
-                if ( !JOB_NAME.contains('merge') ) {
+                if ( ! isMergeJob ) {
                     REV="/"+"${GERRIT_REFSPEC}".replaceAll('/','-')
                 }
                 channel="latest"
@@ -150,7 +151,7 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
             def directory = charmPath
             CHECK_CHANGES = "git diff --name-only origin/$GERRIT_BRANCH -- $directory |wc -l"
             charmsChanged = sh(returnStdout:true,  script: CHECK_CHANGES).trim()
-            if (charmsChanged != "0") {
+            if (charmsChanged != "0" || isMergeJob) {
                 println("$directory has changes, rebuilding")
 
                 parallelSteps[directory] = {
@@ -166,7 +167,7 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
                     try {
                         dir("${directory}") {
                             try {
-                                sh "charmcraft pack --format json --verbosity brief 1> pack.json 2> pack-stderr.log"
+                                sh "charmcraft pack --force --format json --verbosity brief 1> pack.json 2> pack-stderr.log"
                             } catch (Exception e) {
                                 sh "cat pack-stderr.log"
                                 throw e
@@ -182,6 +183,13 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
                                     println("Uploading $resourceName")
                                     sh "charmcraft upload --format json --verbosity brief $resourceName 1> upload.json 2> upload-stderr.log"
                                 } catch (Exception e) {
+                                    def errorMessage = sh(
+                                        returnStdout: true,
+                                        script: 'cat upload.json | jq -r ".errors[0].message" | grep -v null').trim()
+                                    if (errorMessage.contains("already exists")) {
+                                        println("No changes, skipping upload")
+                                        return 0
+                                    }
                                     sh "cat upload-stderr.log"
                                     throw e
                                 }