jenkins trigger build if new tag is released
Solution 1
What do you mean by new tag? Does it has some template name?
You can surely define it in Advanced --> Refspec -->refs/tags/{tagname}
.
You can even do refs/tags/*
for finding really ANY new tags.
Solution 2
Set refspec to: +refs/tags/*:refs/remotes/origin/tags/*
branch specifier: **
Under build triggers check Build when a change is pushed to GitHub
Solution 3
Please note that the approach in the answer provided by stanjer doesn't make Jenkins trigger builds on new tags if they point to commits that were built before. For example, you tag release v1.0.0 (to make jenkins deploy this release), then on the future you have to rollback to v1.0.0, tagging its commit again, but with v1.0.0-rollback, Jenkins won't deploy your rollback because it will check the hash the tag points to, not the hash of the tag itself.
In summary, jenkins will only build new tags if they point to commits that are not tagged already, and this is currently not tweakable.
It would be awesome if one could use Jenkins as a CD tool working with tags for deploys and rollbacks.
More info here https://groups.google.com/forum/#!msg/jenkinsci-users/mYxtDNMz1ZI/xbX9-xM9BQAJ
Solution 4
Previous doesn't work for me. In my case works refspec in single quotes:
Refspec: '+refs/tags/*':'refs/remotes/origin/tags/*' Branch Specifier: **/tags/**
I have Jenkins 2.120. To make job work which is triggered by tag need to do the following steps:
create job with:
Refspec: '+refs/tags/*':'refs/remotes/origin/tags/*'
Branch Specifier: **/tags/**
Run build
Reconfigure the same job to parameters:
Refspec: '+refs/tags/*':'refs/remotes/origin/tags/*'
Branch Specifier: **
Run build
Reconfigure the same job to parameters:
Refspec: '+refs/tags/*':'refs/remotes/origin/tags/*' Branch Specifier: **/tags/**
Run the build
Only after this magic steps, when I tag the branch it automatically trigger Jenkins
Solution 5
Combined @albertski and @Sergey answers works for me.
Path: Jenkins > {YourJob} > Configure > Pipeline > Definition(Pipeline script from SCM) > SCM(Git)
Options:
Repositories > Advanced... > Refspec +refs/tags/v*:refs/remotes/origin/tags/v*
Branches to build > Branch Specifier (blank for 'any') **/tags/v*
Set v* if you want build tags started with v, such as v0.1.0, v1.0.5...
Comments
-
Kingalione about 3 years
I want to configure jenkins so that it starts building if a new tag is released in any branch of an git repository. How do I configure this behaviour?
Triggering:
Thanks for any help
-
Kingalione about 9 yearsyes i want that jenkins starts building if a new tag is released in the /tags folder. I tried it with adding /tags/* to the branch specifier but it didn't worked for me
-
Stan E about 9 yearshave you tried it how I showed in my answer? You should define a tag group and use them as shown on my screenshot.
-
Kingalione about 9 yearsyes i tried it and it works half. It works if I tag a version to the latest revision not if I tag an older revision. I want that jenkins starts building if a new tag is tagged on any revision. I used +refs/tags/*:refs/remotes/uw/tags/* similar to your example in the refspec. Am I missing something?
-
Stan E about 9 yearsSo, to conclude. My refspec is something like
+refs/tags/*:refs/remotes/origin/tags/*
, my branch is*/tags/*
+ sure you will add SCM polling every N minutes (I have 5). What are you getting after that? -
Kingalione about 9 yearsI have updated my post with my current configuration which allows me to trigger the build if I tag the latest revision not any revision. thanks for your help
-
Kingalione about 9 yearsWell I found out that if I do no changes in the source jenkins will not start building the tag even if its the latest revision. But in our case it is neccessary to trigger the building even if there are no changes in the source. If a new tag is created, jenkins should build it no matter what.
-
Kingalione about 9 yearsIs it clear what I mean? Excuse me for my bad english
-
Stan E about 9 yearsYes, got it. Git is triggered after polling only if new code persist. It's a major rule for that plugin, so there is no way to make a workaround with only git plugin. The thing that I can advice you is to make 2 tasks. 1st task is running every N minutes and just working with console. You are executing
git describe --tags
as a shell command and get the latest tag from git. Then you are writing the tag in the some property file (for saving that you have already run a task for that tag) and polling another stream where you are passing tag name and building it. -
Antebios over 7 yearsYou forgot the stars for the refspec: +refs/tags/*:refs/remotes/origin/tags/*. Also, the branch specifier (*) didn't help, but "refs/tags/" did it. Now it's only being triggered for tagged commits.
-
Antebios over 7 yearsI stand corrected: branch specifier needs to be
**
. Let me explain why: If you did a commit, then Jenkins job polled the repo, then you tagged... Jenkins will not detect the change. If you left branch specifier as**
, then did the same process, then your new tag will be detected even if no new commit was introduced. SO, user "albertski" almost had the correct answer, just add the ASTERISK after "tags/". -
Antebios over 7 yearsAs what albertski said below, this is what worked for me: Set refspec to:
+refs/tags/*:refs/remotes/origin/tags/*
and finally set branch specifier:**
-
Andrew over 6 yearsThere's been progress on this: github.com/jenkinsci/github-branch-source-plugin/pull/158 looks pretty close to merge.
-
Dan M. over 5 years@Andrew hm, why is in github plugin, not a general git plugin?
-
uberrebu about 5 yearshow can one achieve this with groovy job DSL script?stackoverflow.com/questions/54930947/…
-
TangHongWan about 5 yearsThis also does not work for me. I added hook on github side and can see the hook is correctly triggered on github (enterprise version). But still cannot trigger the job run on Jenkins. The git plugin is installed and build triggers "GitHub hook trigger for GITScm polling" is also checked. Don't know why it's does not work. But when I change the event to "Pushes" on github, then the trigger will work! So the question is how to get jenkins job triggered when tag created?