jdk14-alpine/Jenkinsfile

46 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

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 {
image 'alpine:3.17.3'
2023-03-30 17:58:04 +02:00
// Mount docker socket for docker-in-docker
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
stages {
stage('prepare') {
steps {
2023-03-30 18:18:16 +02:00
sh "apk update && apk add --no-cache git docker-cli"
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 {
sh "docker build . --tag ${resolveImageName(env)}"
}
}
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)}"
}
}
}
}