3

I want to trigger jenkins build if a new tag is pushed to a remote repository. I have seen number of posts, but none seems to be working for me. My build is triggered successfully when I push a tag having new commits in it, but if I push a new tag on old commits it does not trigger the build.

I have configured it using git plugin in Jenkins and adding Refscpec value as +refs/tags/*:refs/remotes/origin/tags/* and Branch specifier as */tags/*

Now if I run:

git push origin master
git tag release-beta
git push origin release-beta
git tag release-prod
git push origin release-prod

Build is triggered successfully for tag release-beta but not for release-prod.

This means jenkins is always looking for commit ids, if there is a new commit id linked with the tag it will build the job.

I want to merge my code to master branch, tag it as 'release-beta' and deploy to beta pipeline. Once beta testing is complete, I want to tag the same code as 'release-prod' and deploy the production pipeline from same jenkins job.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
jass
  • 343
  • 3
  • 15

1 Answers1

0

https://github.com/jenkinsci/generic-webhook-trigger-plugin might be worth looking at since it should allow you to trigger builds for tags only by filtering on ref (for instance, ^(refs/tags/.+)$ ) :

{
  "before": "1848f1236ae15769e6b31e9c4477d8150b018453",
  "after": "5cab18338eaa83240ab86c7b775a9b27b51ef11d",
  "ref": "refs/heads/develop"
}

This would involve creating a Webhook trigger from your repository manager to http://$YOUR_JENKINS_HOME_URL/jenkins/generic-webhook-trigger/invoke?token=abc123 and of course assumes that your repository manager supports Webhooks to begin with.


Unfortunately, with regards to native support via the git-plugin, this is currently an open issue : https://issues.jenkins-ci.org/browse/JENKINS-14917

enter image description here

And there is a corresponding SO question with much more detail and traction around this : Trigger a Jenkins pipeline by tagging an existing commit

Ashutosh Jindal
  • 18,501
  • 4
  • 62
  • 91