Adding resource 47/12547/1
authorMark Beierl <mark.beierl@canonical.com>
Thu, 15 Sep 2022 18:12:55 +0000 (14:12 -0400)
committerMark Beierl <mark.beierl@canonical.com>
Thu, 15 Sep 2022 18:12:55 +0000 (14:12 -0400)
Turns out we do need to be explicit on image resource
revision to use when publishing a charm to a new
track/branch

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

index fa94d4b..e4b63d4 100644 (file)
@@ -171,15 +171,14 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
                                     throw e
                                 }
 
-                                def resourceName = sh(
+                                def charmFilename = 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 {
-                                        println("Uploading $resourceName")
-                                        sh "charmcraft upload --format json --verbosity brief $resourceName 1> upload.json 2> upload-stderr.log"
+                                        println("Uploading $charmFilename")
+                                        sh "charmcraft upload --format json --verbosity brief $charmFilename 1> upload.json 2> upload-stderr.log"
                                     } catch (Exception e) {
                                         def errorMessage = sh(
                                             returnStdout: true,
@@ -209,7 +208,29 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
                                     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 resourceArgument = ""
+                                    try {
+                                        def resourceName = sh(
+                                            returnStdout:true,
+                                            script: "cat metadata.yaml | yq '.resources | keys | .[0]'").trim()
+
+                                        resourceArgument = "--resource $resourceName:1"
+
+                                        resourceName = sh(
+                                            returnStdout:true,
+                                            script: "cat metadata.yaml | yq '.resources | keys | .[1]'").trim()
+                                        if( resourceName != "null" ) {
+                                            resourceArgument += " --resource $resourceName:1"
+                                        }
+
+                                    } catch (Exception discard) {
+                                        print("No resource associated with bundle, skipping")
+                                    }
+
+                                    print("resourceArgument = $resourceArgument")
+
+                                    sh "charmcraft release ${charmName} --revision=${charmRevision} ${resourceArgument} --channel=${channel}/edge/${charmBranch}"
                                 }
                             }
                         } finally {