Use branch for charms 40/12840/1
authorMark Beierl <mark.beierl@canonical.com>
Thu, 12 Jan 2023 20:14:58 +0000 (15:14 -0500)
committerbeierlm <mark.beierl@canonical.com>
Mon, 16 Jan 2023 19:11:29 +0000 (20:11 +0100)
When merging changes for charms in a development branch (ie: not v10.0, etc),
we want to publish it to latest/edge/branch-name so that it can be kept
separate from the other branches of development

Change-Id: I8f2ec65057d2029d7cda83b9b607a0474a801455
Signed-off-by: Mark Beierl <mark.beierl@canonical.com>
(cherry picked from commit 27da38deb3b184608a6d66ab6bc476506d8d7301)

jenkins/ci-pipelines/ci_stage_2.groovy

index 44e6ae9..a6dcfa4 100644 (file)
@@ -201,7 +201,7 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
                                     def channel="latest"
                                     if (BRANCH_NAME.startsWith("v")) {
                                         channel=BRANCH_NAME.substring(1)
-                                    } else if (BRANCH_NAME!="master") {
+                                    } else if (BRANCH_NAME!="master" && JOB_NAME.contains('merge')) {
                                         charmBranch=BRANCH_NAME
                                     }
 
@@ -213,15 +213,28 @@ def ci_pipeline(mdg,url_prefix,project,branch,refspec,revision,do_stage_3,artifa
                                     try {
                                         def resourceName = sh(
                                             returnStdout:true,
-                                            script: "cat metadata.yaml | yq '.resources | keys | .[0]'").trim()
+                                            script: "cat metadata.yaml | yq '.resources | keys | .[0]'"
+                                        ).trim()
+                                        if( resourceName != "null" ) {
+                                            sh "charmcraft resource-revisions $charmName $resourceName | head -2 | tail -1 | awk '{print \$1}'"
+                                            def resourceVers = sh(
+                                                returnStdout:true,
+                                                script: "charmcraft resource-revisions $charmName $resourceName | head -2 | tail -1 | awk '{print \$1}'"
+                                            ).trim()
 
-                                        resourceArgument = "--resource $resourceName:1"
+                                            resourceArgument = "--resource $resourceName:$resourceVers"
 
-                                        resourceName = sh(
-                                            returnStdout:true,
-                                            script: "cat metadata.yaml | yq '.resources | keys | .[1]'").trim()
-                                        if( resourceName != "null" ) {
-                                            resourceArgument += " --resource $resourceName:1"
+                                            resourceName = sh(
+                                                returnStdout:true,
+                                                script: "cat metadata.yaml | yq '.resources | keys | .[1]'").trim()
+
+                                            if( resourceName != "null" ) {
+                                                resourceVers = sh(
+                                                    returnStdout:true,
+                                                    script: "charmcraft resource-revisions $charmName $resourceName | head -2 | tail -1 | awk '{print \$1}'"
+                                                ).trim()
+                                                resourceArgument += " --resource $resourceName:$resourceVers"
+                                            }
                                         }
 
                                     } catch (Exception discard) {