Fix tag matching

This commit is contained in:
myrmidex 2025-07-14 21:01:41 +02:00
parent 2fed772e47
commit 53bcce2b98

22
Jenkinsfile vendored
View file

@ -3,12 +3,10 @@ pipeline {
triggers { triggers {
GenericTrigger( GenericTrigger(
causeString: 'Triggered on tag push', causeString: 'Triggered by push event',
token: 'tag-trigger-secret', token: 'tag-trigger-secret',
printContributedVariables: true, printContributedVariables: true,
printPostContent: true, printPostContent: true,
regexpFilterExpression: 'ref=refs/tags/.*\nafter=(?!0{40}).*',
regexpFilterText: '$ref\n$after',
genericVariables: [ genericVariables: [
[key: 'ref', value: '$.ref'], [key: 'ref', value: '$.ref'],
[key: 'after', value: '$.after'] [key: 'after', value: '$.after']
@ -23,22 +21,30 @@ pipeline {
} }
stages { stages {
stage('Tag Check') { stage('Tag Push Filter') {
steps { steps {
script { script {
def isTag = sh(script: 'git describe --tags --exact-match || echo "nope"', returnStdout: true).trim() if (!env.ref?.startsWith('refs/tags/')) {
if (isTag == "nope") { echo "Not a tag push (ref = ${env.ref}). Skipping build."
echo "Not a tag. Skipping build."
currentBuild.result = 'NOT_BUILT' currentBuild.result = 'NOT_BUILT'
return return
} }
if (env.after == null || env.after ==~ /^0{40}$/) {
echo "After SHA is null or zeroed (after = ${env.after}). Skipping build."
currentBuild.result = 'NOT_BUILT'
return
}
echo "Valid tag push detected: ${env.ref} (${env.after})"
} }
} }
} }
stage('Build & Push Docker Image') { stage('Build & Push Docker Image') {
when { when {
expression { expression {
return env.GIT_COMMIT && env.GIT_COMMIT != "" return env.ref?.startsWith('refs/tags/') && env.GIT_COMMIT && env.GIT_COMMIT != ""
} }
} }
steps { steps {