From 6cc6c5ef36240998bbb8fc935ba20701ed856ea0 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 11 Jan 2024 09:49:50 -0600 Subject: [PATCH] bci2: Add defaultBranch keyword argument Passing the `defaultBranch` argument to `buildContainerImage2()` allows setting the `latest` for projects where the default branch is not *main*. For example: ```groovy buildContainerImage2(defaultBranch: 'master') ``` This will update the `latest` tag whenever a new build is created on the *master* branch. --- vars/buildContainerImage2.groovy | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vars/buildContainerImage2.groovy b/vars/buildContainerImage2.groovy index f9db4d9..2061bff 100644 --- a/vars/buildContainerImage2.groovy +++ b/vars/buildContainerImage2.groovy @@ -7,6 +7,7 @@ def call(args) { def tag = args?.tag def archlist = args?.archlist def schedule = args?.schedule + def defaultBranch = args?.defaultBranch properties([ pipelineTriggers([cron(schedule ?: 'H H H * *')]) @@ -27,6 +28,9 @@ def call(args) { if (archlist == null) { archlist = ['amd64'] } + if (defaultBranch == null) { + defaultBranch = 'main' + } def repo = "${registry}/${project}/${name}" def full_name = "${repo}:${tag}" @@ -72,7 +76,7 @@ def call(args) { } sh "buildah push ${full_name} ${full_name}-${env.BUILD_NUMBER}" sh "buildah push ${full_name}" - if (env.BRANCH_NAME == 'main') { + if (env.BRANCH_NAME == defaultBranch) { sh "buildah push ${full_name} ${repo}:latest" } }