jdk14-alpine/Jenkinsfile

55 lines
1.7 KiB
Plaintext
Raw 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 {
2023-04-04 19:07:59 +02:00
image 'alpine:3.17.3'
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 19:08:50 +02:00
apk add git curl
2023-04-04 18:40:52 +02:00
"""
2023-04-04 19:07:59 +02:00
sh """curl -fsSLO https://get.docker.com/builds/Linux/x86_64/docker-17.04.0-ce.tgz \
&& tar xzvf docker-17.04.0-ce.tgz \
&& mv docker/docker /usr/local/bin \
&& rm -r docker docker-17.04.0-ce.tgz"""
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:07:59 +02:00
sh "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)}"
}
}
}
}