jdk14-alpine/Jenkinsfile

49 lines
1.5 KiB
Groovy

def resolveImageTag(env) {
return env.TAG_NAME?.replace(env.RELEASE_TAG_PREFIX, '') ?: 'latest'
}
def resolveImageName(env) {
return "${env.REGISTRY_HOST}/docker-base-images/${env.IMAGE_BASE_NAME}:${resolveImageTag(env)}"
}
pipeline {
agent {
docker {
image 'alpinelinux/docker-cli'
// Mount docker socket for docker-in-docker
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
stages {
stage('prepare') {
steps {
sh """
apk update && \
apk add --no-cache git
"""
script {
env.IMAGE_BASE_NAME = "jdk14-alpine"
env.RELEASE_TAG_PREFIX = "release-"
env.REGISTRY_HOST = "git.tswf.io"
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 {
tag "${env.RELEASE_TAG_PREFIX}*"
}
steps {
sh "docker login ${env.REGISTRY_HOST} -u ${env.GITEA_USER} -p ${env.GITEA_OAUTH_TOKEN}"
sh "docker image push ${resolveImageName(env)}"
}
}
}
}