2023-03-30 17:58:04 +02:00
|
|
|
def resolveImageTag(env) {
|
2023-03-30 18:16:56 +02:00
|
|
|
return env.TAG_NAME?.replace(env.RELEASE_TAG_PREFIX, '') ?: 'latest'
|
2023-03-30 17:58:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def resolveImageName(env) {
|
2023-03-30 18:16:56 +02:00
|
|
|
return "${env.REGISTRY_HOST}/docker-base-images/${env.IMAGE_BASE_NAME}:${resolveImageTag(env)}"
|
2023-03-30 17:58:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pipeline {
|
|
|
|
agent {
|
|
|
|
docker {
|
2023-04-04 18:59:59 +02:00
|
|
|
image 'alpinelinux/docker-cli'
|
2023-03-30 17:58:04 +02:00
|
|
|
// Mount docker socket for docker-in-docker
|
2023-04-04 18:56:17 +02:00
|
|
|
args '-v /var/run/docker.sock:/var/run/docker.sock'
|
2023-03-30 17:58:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('prepare') {
|
|
|
|
steps {
|
2023-04-04 18:40:52 +02:00
|
|
|
sh """
|
|
|
|
apk update && \
|
2023-04-04 18:59:59 +02:00
|
|
|
apk add --no-cache git
|
2023-04-04 18:40:52 +02:00
|
|
|
"""
|
2023-03-30 17:58:04 +02:00
|
|
|
script {
|
2023-03-30 18:16:56 +02:00
|
|
|
env.IMAGE_BASE_NAME = "jdk14-alpine"
|
|
|
|
env.RELEASE_TAG_PREFIX = "release-"
|
|
|
|
env.REGISTRY_HOST = "git.tswf.io"
|
2023-03-30 17:58:04 +02:00
|
|
|
if (env.TAG_NAME == null) {
|
|
|
|
env.TAG_NAME = sh(returnStdout: true, script: "git tag --points-at HEAD").trim()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('build_docker') {
|
|
|
|
steps {
|
2023-04-04 19:05:01 +02:00
|
|
|
sh "which docker"
|
|
|
|
sh "/usr/bin/docker build . --tag ${resolveImageName(env)}"
|
2023-03-30 17:58:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('push_docker') {
|
|
|
|
when {
|
2023-03-30 18:16:56 +02:00
|
|
|
tag "${env.RELEASE_TAG_PREFIX}*"
|
2023-03-30 17:58:04 +02:00
|
|
|
}
|
|
|
|
steps {
|
2023-03-30 18:16:56 +02:00
|
|
|
sh "docker login ${env.REGISTRY_HOST} -u ${env.GITEA_USER} -p ${env.GITEA_OAUTH_TOKEN}"
|
2023-03-30 17:58:04 +02:00
|
|
|
sh "docker image push ${resolveImageName(env)}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|