pipeline { agent any stages { stage('TEST') { steps { script { CUSTOM_TAG = sh(returnStdout: true, script: "git tag --contains").trim() echo CUSTOM_TAG } echo sh(script: 'env|sort', returnStdout: true) echo "${CUSTOM_TAG}" } } stage('ONLY ON TAG') { when { buildingTag() } steps { echo "I run only because I am on tag ${CUSTOM_TAG}" } } } }