ci: use latest and stable Docker tags based on job name

Also use Git commit by default if no tag is provided, but do not push.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2023-09-22 15:09:01 +02:00
parent 9f4754dcae
commit 735c2fa0d7
No known key found for this signature in database
GPG Key ID: FE65CD384D5BF7B4
1 changed files with 12 additions and 3 deletions

View File

@ -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 ''
}
}