incr/Jenkinsfile
2025-07-13 21:55:03 +02:00

52 lines
1.4 KiB
Groovy

pipeline {
agent any
environment {
REGISTRY = 'codeberg.org'
IMAGE_NAME = "${REGISTRY}/lvl0/incr"
DOCKER_CREDENTIALS_ID = 'codeberg-registry' // Jenkins credentials ID
}
stages {
stage('Detect Tag') {
steps {
script {
def tag = sh(script: 'git describe --tags --exact-match || true', returnStdout: true).trim()
if (tag) {
env.GIT_TAG = tag
echo "✅ Detected tag: ${tag}"
} else {
echo "⛔ No tag detected — skipping build"
currentBuild.result = 'SUCCESS'
error("Skipping non-tag build")
}
}
}
}
stage('Build Docker Image') {
steps {
echo "⚙️ Building Docker image: ${IMAGE_NAME}:${GIT_TAG}"
sh "docker build -f docker/Dockerfile -t ${IMAGE_NAME}:${GIT_TAG} ."
}
}
stage('Push to Registry') {
steps {
echo "📤 Pushing Docker image: ${IMAGE_NAME}:${GIT_TAG}"
withCredentials([
usernamePassword(
credentialsId: DOCKER_CREDENTIALS_ID,
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD'
)
]) {
sh """
echo "${PASSWORD}" | docker login ${REGISTRY} -u "${USERNAME}" --password-stdin
docker push ${IMAGE_NAME}:${GIT_TAG}
"""
}
}
}
}
}