2021-10-26 14:33:46 +00:00
|
|
|
pipeline {
|
|
|
|
agent {
|
2023-04-03 15:28:16 +00:00
|
|
|
label 'linux && x86_64'
|
2021-10-26 14:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parameters {
|
|
|
|
string(
|
2023-04-18 16:26:43 +00:00
|
|
|
name: 'GIT_REF',
|
2021-10-26 14:33:46 +00:00
|
|
|
defaultValue: 'master',
|
2023-04-18 16:26:43 +00:00
|
|
|
description: 'Branch, tag, or commit to build.'
|
2021-10-26 14:33:46 +00:00
|
|
|
)
|
|
|
|
string(
|
|
|
|
name: 'IMAGE_NAME',
|
|
|
|
description: 'Docker image name.',
|
2023-11-28 14:15:18 +00:00
|
|
|
defaultValue: params.IMAGE_NAME ?: 'waku-org/go-waku',
|
2021-10-26 14:33:46 +00:00
|
|
|
)
|
|
|
|
string(
|
|
|
|
name: 'IMAGE_TAG',
|
2023-04-18 16:26:43 +00:00
|
|
|
description: 'Docker image tag.',
|
2023-11-09 15:45:25 +00:00
|
|
|
defaultValue: getDefaultImageTag(params.IMAGE_TAG)
|
2023-09-20 10:44:01 +00:00
|
|
|
)
|
|
|
|
string(
|
|
|
|
name: 'DOCKER_CRED',
|
2023-11-28 14:15:18 +00:00
|
|
|
description: 'Name of Docker Registry credential.',
|
|
|
|
defaultValue: params.DOCKER_CRED ?: 'harbor-wakuorg-robot',
|
2021-10-26 14:33:46 +00:00
|
|
|
)
|
2023-11-28 14:15:18 +00:00
|
|
|
string(
|
|
|
|
name: 'DOCKER_REGISTRY_URL',
|
|
|
|
description: 'URL of the Docker Registry',
|
|
|
|
defaultValue: params.DOCKER_REGISTRY_URL ?: 'https://harbor.status.im'
|
|
|
|
)
|
|
|
|
|
2021-10-26 14:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
options {
|
|
|
|
timestamps()
|
|
|
|
buildDiscarder(logRotator(
|
|
|
|
numToKeepStr: '10',
|
|
|
|
daysToKeepStr: '30',
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
stages {
|
|
|
|
stage('Build') {
|
|
|
|
steps { script {
|
|
|
|
image = docker.build(
|
2024-09-11 07:23:26 +00:00
|
|
|
"${params.IMAGE_NAME}:${params.IMAGE_TAG ?: GIT_COMMIT.take(8)}",
|
|
|
|
"--build-arg='GIT_COMMIT=${GIT_COMMIT.take(8)}' ."
|
2021-10-26 14:33:46 +00:00
|
|
|
)
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Push') {
|
2023-09-22 13:09:01 +00:00
|
|
|
when { expression { params.IMAGE_TAG != '' } }
|
2021-10-26 14:33:46 +00:00
|
|
|
steps { script {
|
|
|
|
withDockerRegistry([
|
2023-11-28 14:15:18 +00:00
|
|
|
credentialsId: params.DOCKER_CRED, url: params.DOCKER_REGISTRY_URL
|
2021-10-26 14:33:46 +00:00
|
|
|
]) {
|
|
|
|
image.push()
|
2023-09-20 13:53:35 +00:00
|
|
|
/* If Git ref is a tag push it as Docker tag too. */
|
2023-09-22 13:09:01 +00:00
|
|
|
if (params.GIT_REF ==~ /v\d+\.\d+\.\d+.*/) {
|
2023-09-20 13:53:35 +00:00
|
|
|
image.push(params.GIT_REF)
|
|
|
|
}
|
2021-10-26 14:33:46 +00:00
|
|
|
}
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
post {
|
|
|
|
always { cleanWs() }
|
|
|
|
}
|
|
|
|
}
|
2022-10-12 13:31:11 +00:00
|
|
|
|
2023-11-09 15:45:25 +00:00
|
|
|
def getDefaultImageTag(currentValue) {
|
2023-09-22 13:09:01 +00:00
|
|
|
switch (env.JOB_BASE_NAME) {
|
|
|
|
case 'docker-latest': return 'latest'
|
|
|
|
case 'docker-release': return 'stable'
|
2023-11-09 15:45:25 +00:00
|
|
|
case 'docker-manual': return ''
|
|
|
|
default: return currentValue
|
2023-09-22 13:09:01 +00:00
|
|
|
}
|
|
|
|
}
|