Fixing typo 44/12544/3
authorMark Beierl <mark.beierl@canonical.com>
Wed, 14 Sep 2022 16:56:12 +0000 (12:56 -0400)
committerMark Beierl <mark.beierl@canonical.com>
Wed, 14 Sep 2022 18:12:54 +0000 (14:12 -0400)
Typo in check to see if this is a merge job and should skip
the releasenote check
Only rebuild charms if they exist in the module

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

index e3e86c5..fa94d4b 100644 (file)
@@ -52,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 (!sMergeJob) {
+        if (!isMergeJob) {
             sh "devops-stages/stage-releasenote.sh"
         }
         else {
@@ -146,73 +146,75 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
         concurrency = sh(returnStdout: true, script: "expr `nproc` / 2").trim() as int
         for (charmPath in charms) {
             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" || isMergeJob) {
-                println("$directory has changes, rebuilding")
-
-                parallelSteps[directory] = {
-                    waitUntil(quiet: true, initialRecurrencePeriod: 5) {
-                        if (concurrency > 0) {
-                            concurrency--
-                            true
-                        } else {
-                            sleep 5
-                            false
-                        }
-                    }
-                    try {
-                        dir("${directory}") {
-                            try {
-                                sh "charmcraft pack --format json --verbosity brief 1> pack.json 2> pack-stderr.log"
-                            } catch (Exception e) {
-                                sh "cat pack-stderr.log"
-                                throw e
+            if (fileExists("$charmPath/charmcraft.yaml")) {
+                CHECK_CHANGES = "git diff --name-only origin/$GERRIT_BRANCH -- $directory |wc -l"
+                charmsChanged = sh(returnStdout:true,  script: CHECK_CHANGES).trim()
+                if (charmsChanged != "0" || isMergeJob) {
+                    println("$directory has changes, rebuilding")
+
+                    parallelSteps[directory] = {
+                        waitUntil(quiet: true, initialRecurrencePeriod: 5) {
+                            if (concurrency > 0) {
+                                concurrency--
+                                true
+                            } else {
+                                sleep 5
+                                false
                             }
-
-                            def resourceName = sh(
-                                returnStdout: true,
-                                script: 'cat pack.json | jq -r ".charms[0], .bundles[0]" | grep -v null').trim()
-
-                            withCredentials([string(credentialsId: 'Charmstore', variable: 'CHARMCRAFT_AUTH')]) {
-                                commandOutput = sh(returnStdout:true, script: "charmcraft whoami")
+                        }
+                        try {
+                            dir("${directory}") {
                                 try {
-                                    println("Uploading $resourceName")
-                                    sh "charmcraft upload --format json --verbosity brief $resourceName 1> upload.json 2> upload-stderr.log"
+                                    sh "charmcraft pack --format json --verbosity brief 1> pack.json 2> pack-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"
+                                    sh "cat pack-stderr.log"
                                     throw e
                                 }
-                                def charmRevision = sh(
+
+                                def resourceName = sh(
                                     returnStdout: true,
-                                    script: 'cat upload.json | jq -r ".revision"').trim()
+                                    script: 'cat pack.json | jq -r ".charms[0], .bundles[0]" | grep -v null').trim()
+
+                                withCredentials([string(credentialsId: 'Charmstore', variable: 'CHARMCRAFT_AUTH')]) {
+                                    commandOutput = sh(returnStdout:true, script: "charmcraft whoami")
+                                    try {
+                                        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
+                                    }
+                                    def charmRevision = sh(
+                                        returnStdout: true,
+                                        script: 'cat upload.json | jq -r ".revision"').trim()
 
-                                def charmBranch="merged"
-                                if ( !JOB_NAME.contains('merge') ) {
-                                    charmBranch="${GERRIT_REFSPEC}".replaceAll('/','-')
-                                }
-                                def channel="latest"
-                                if (BRANCH_NAME.startsWith("v")) {
-                                    channel=BRANCH_NAME.substring(1)
-                                } else if (BRANCH_NAME!="master") {
-                                    REV="/"+BRANCH_NAME+REV.replaceAll('/','-')
-                                }
+                                    def charmBranch="merged"
+                                    if ( !JOB_NAME.contains('merge') ) {
+                                        charmBranch="${GERRIT_REFSPEC}".replaceAll('/','-')
+                                    }
+                                    def channel="latest"
+                                    if (BRANCH_NAME.startsWith("v")) {
+                                        channel=BRANCH_NAME.substring(1)
+                                    } else if (BRANCH_NAME!="master") {
+                                        REV="/"+BRANCH_NAME+REV.replaceAll('/','-')
+                                    }
 
-                                def charmName = sh(
-                                    returnStdout:true,
-                                    script: "if [ -f bundle.yaml ];then cat bundle.yaml;else cat metadata.yaml;fi|yq -r .name").trim()
-                                sh "charmcraft release ${charmName} --revision=${charmRevision} --channel=${channel}/edge/${charmBranch}"
+                                    def charmName = sh(
+                                        returnStdout:true,
+                                        script: "if [ -f bundle.yaml ];then cat bundle.yaml;else cat metadata.yaml;fi|yq -r .name").trim()
+                                    sh "charmcraft release ${charmName} --revision=${charmRevision} --channel=${channel}/edge/${charmBranch}"
+                                }
                             }
+                        } finally {
+                            concurrency++
                         }
-                    } finally {
-                        concurrency++
                     }
                 }
             }