From 735c2fa0d75d192b6fa0b8b9ef3655593efc591e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Fri, 22 Sep 2023 15:09:01 +0200 Subject: [PATCH] ci: use latest and stable Docker tags based on job name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also use Git commit by default if no tag is provided, but do not push. Signed-off-by: Jakub SokoĊ‚owski --- ci/Jenkinsfile.docker | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ci/Jenkinsfile.docker b/ci/Jenkinsfile.docker index 175b1bd4..127e6821 100644 --- a/ci/Jenkinsfile.docker +++ b/ci/Jenkinsfile.docker @@ -17,7 +17,7 @@ pipeline { string( name: 'IMAGE_TAG', description: 'Docker image tag.', - defaultValue: env.JOB_BASE_NAME == 'release' ? 'stable' : 'deploy-test', + defaultValue: getDefaultImageTag() ) string( name: 'DOCKER_CRED', @@ -38,20 +38,21 @@ pipeline { stage('Build') { steps { script { image = docker.build( - "${params.IMAGE_NAME}:${params.IMAGE_TAG}", + "${params.IMAGE_NAME}:${params.IMAGE_TAG ?: GIT_COMMIT.take(8)}", "--build-arg='GIT_COMMIT=${GIT_COMMIT.take(8)}' ." ) } } } stage('Push') { + when { expression { params.IMAGE_TAG != '' } } steps { script { withDockerRegistry([ credentialsId: params.DOCKER_CRED, url: '' ]) { image.push() /* If Git ref is a tag push it as Docker tag too. */ - if (env.GIT_BRANCH ==~ /v\d+\.\d+\.\d+.*/) { + if (params.GIT_REF ==~ /v\d+\.\d+\.\d+.*/) { image.push(params.GIT_REF) } } @@ -107,3 +108,11 @@ def discordNotify(Map args=[:]) { ) } } + +def getDefaultImageTag() { + switch (env.JOB_BASE_NAME) { + case 'docker-latest': return 'latest' + case 'docker-release': return 'stable' + default: return '' + } +}