We are using the Git Plugin : https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
Currently, via webhooks we start a Jenkins build whenever a change is pushed to GitHub. Now we want to trigger the same build when a new tag is added. So we have two triggering conditions :
If we try the fix mention in this thread then the builds start only for tags. jenkins trigger build if new tag is released
How can we do it for both scenarios ?
Question # 02 : How can we get the tag name inside a Jenkins build, is there any environment variable for it.
4 Step Process:
git commit -m "Some meaningful message"
git tag -a release_stage_<meaningful tag>
git tag -a release_production_<meaningful tag>
git push origin release_stage_<same_meaningful_tag>
git push origin <branch_name>
Jenkins File:
properties([pipelineTriggers([[$class: 'GitHubPushTrigger']])])
checkout scm
git_branch = env.BRANCH_NAME
git_branch_to_release = env.BRANCH_NAME
git_tag = sh returnStdout: true, script: 'git tag -l --points-at HEAD'```
`//And now you can use to do anything with tags`
if(currentBuild.result=='SUCCESSFUL' || currentBuild.result=='SUCCESS' || currentBuild.result == null)
{
if (git_tag.contains('release_stage') || git_tag.contains('release_production'))
{
// Do anything which you want to do with tags
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With