Add Jenkins SCM webhook
This commit is contained in:
parent
df34ebbc1f
commit
3eea28979e
1 changed files with 20 additions and 28 deletions
50
Jenkinsfile
vendored
50
Jenkinsfile
vendored
|
|
@ -1,49 +1,41 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
|
triggers {
|
||||||
|
githubPush() // Enables webhook support via GitHub-style POST
|
||||||
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
REGISTRY = 'codeberg.org'
|
REGISTRY = 'codeberg.org'
|
||||||
IMAGE_NAME = "${REGISTRY}/lvl0/incr"
|
IMAGE_NAME = "${REGISTRY}/lvl0/incr"
|
||||||
DOCKER_CREDENTIALS_ID = 'codeberg-registry' // Jenkins credentials ID
|
DOCKER_CREDENTIALS_ID = 'codeberg-registry'
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Detect Tag') {
|
stage('Tag Check') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def tag = sh(script: 'git describe --tags --exact-match || true', returnStdout: true).trim()
|
def isTag = sh(script: 'git describe --tags --exact-match || echo "nope"', returnStdout: true).trim()
|
||||||
if (tag) {
|
if (isTag == "nope") {
|
||||||
env.GIT_TAG = tag
|
echo "Not a tag. Skipping build."
|
||||||
echo "✅ Detected tag: ${tag}"
|
currentBuild.result = 'NOT_BUILT'
|
||||||
} else {
|
return
|
||||||
echo "⛔ No tag detected — skipping build"
|
|
||||||
currentBuild.result = 'SUCCESS'
|
|
||||||
error("Skipping non-tag build")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stage('Build & Push Docker Image') {
|
||||||
stage('Build Docker Image') {
|
when {
|
||||||
|
expression {
|
||||||
|
return env.GIT_COMMIT && env.GIT_COMMIT != ""
|
||||||
|
}
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
echo "⚙️ Building Docker image: ${IMAGE_NAME}:${GIT_TAG}"
|
sh 'docker build -t $IMAGE_NAME:$GIT_COMMIT .'
|
||||||
sh "docker build -f docker/Dockerfile -t ${IMAGE_NAME}:${GIT_TAG} ."
|
withCredentials([usernamePassword(credentialsId: "$DOCKER_CREDENTIALS_ID", usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Push to Registry') {
|
|
||||||
steps {
|
|
||||||
echo "📤 Pushing Docker image: ${IMAGE_NAME}:${GIT_TAG}"
|
|
||||||
withCredentials([
|
|
||||||
usernamePassword(
|
|
||||||
credentialsId: DOCKER_CREDENTIALS_ID,
|
|
||||||
usernameVariable: 'USERNAME',
|
|
||||||
passwordVariable: 'PASSWORD'
|
|
||||||
)
|
|
||||||
]) {
|
|
||||||
sh """
|
sh """
|
||||||
echo "${PASSWORD}" | docker login ${REGISTRY} -u "${USERNAME}" --password-stdin
|
echo "$PASSWORD" | docker login $REGISTRY -u "$USERNAME" --password-stdin
|
||||||
docker push ${IMAGE_NAME}:${GIT_TAG}
|
docker push $IMAGE_NAME:$GIT_COMMIT
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue