Trigger new build only for the latest git tag

80 views
Skip to first unread message

Alex Domoradov

unread,
Sep 4, 2016, 12:26:10 PM9/4/16
to Jenkins Users
Hello,

I have a really simple task - I need to configure jenkins job to build a code only when a new tags with specific names (for e.g. qa_1234567) are pushed to the git (github). I can't use webhooks because I don't have sufficient permissions to repository. So I have to use SCM polling model. I have configured freestyle job and specify the following info

Refspec
+refs/tags/*:refs/remotes/origin/tags/*

Branch Specifier (blank for 'any')
:.*/qa_[0-9]{6,10}$


All works fine except one thing. If I create a new tag and point it to any commit except head - it doesn't work. The job is not triggered. For e.g.

# git rev-parse HEAD
75c42ce06cbbff83e1640e4b7b28543ca6793167

# git tag qa_$(date '+%s') 863c7607 && git push -u origin --tags
Total 0 (delta 0), reused 0 (delta 0)
To ssh://g...@193.243.xxx.xxx:2222/test/p1.git
 * [new tag]         qa_1472930540 -> qa_1472930540



I can see the new tag in SCP Polling log

Seen branch in repository origin/tags/qa_1472930009
Seen branch in repository origin/tags/qa_1472930540
Seen 41 remote branches
Done. Took 0.37 sec
No changes


With head revision all works fine

$ UT=$(date '+%s'); echo ${UT} > 1 && git add . && git commit -m "${UT}" && git push -u origin api
[api 8f80708] 1472931220
 1 file changed, 1 insertion(+), 1 deletion(-)
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 268 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To ssh://g...@193.243.xxx.xxx:2222/test/p1.git
   75c42ce..8f80708  api -> api
Branch api set up to track remote branch api from origin.


$ git tag qa_$(date '+%s') 8f80708  && git push -u origin --tags
Total 0 (delta 0), reused 0 (delta 0)
To ssh://g...@193.243.xxx.xxx:2222/test/p1.git
 * [new tag]         qa_1472931234 -> qa_1472931234

Seen branch in repository origin/tags/qa_1472930009
Seen branch in repository origin/tags/qa_1472930540
Seen branch in repository origin/tags/qa_1472931137
Seen branch in repository origin/tags/qa_1472931234
Seen 43 remote branches
 > git log --full-history --no-abbrev --format=raw -M -m 75c42ce06cbbff83e1640e4b7b28543ca6793167..8f807082e7c7dc3c33ea46dc6146b2bc5d3be3a8 # timeout=10
Done. Took 0.68 sec
Changes found


P.S.
I have read a lot of articles about the subject

http://erics-notes.blogspot.com/2013/05/jenkins-build-latest-git-tag.html
http://www.cyber-tec.org/2015/09/20/build-last-git-tag-with-jenkins/

but can't find any suitable solution

Thanks in advance

conste...@gmail.com

unread,
Oct 18, 2016, 9:35:41 PM10/18/16
to Jenkins Users
bump. i am running into a similar issue. any resolution?

Rachel Moreno

unread,
Oct 20, 2016, 10:15:31 AM10/20/16
to Jenkins Users
Hi,

I don't know if this situation could be happening:

- Hi SCM! I'm a Jenkins job and last time I polled was 000000000000000000 SHA-1 hash. Do you have new content for me?
- Yes, I have new content and new tags from that content.
- Ok, see you, I have a lot of work to do, because I must execute my build steps.
- Wait! Don't forget your new SHA-1 hash 111111111111111111.
...
- Hi SCM! I'm a Jenkins job and last time I polled was 111111111111111111  SHA-1 hash. Do you have new content for me?
- Yes, I have new content, but no tags.
- Oh! So, I have nothing to do. Ok, see you, I gonna take a break.
- Wait! Don't forget your new SHA-1 hash 22222222222222222.
...
- Hi SCM! I'm a Jenkins job and last time I polled was 22222222222222222 SHA-1 hash. Do you have new content for me?
- Yes, I have new tags, but they are referring to previous content.
- Oh! Tags referring to previous content! So, I have nothing to do, because I'm looking for tags referring to commits from my last SHA-1 hash. Ok, see you, I gonna take a break.
- Wait! Don't forget your new SHA-1 hash 333333333333333333.
...

I mean, were there polling executions between committed changes and tag creation referring to some of those commits? If you'd execute polling once at night, and committed changes and tag creation referring to some of those commits (not HEAD) would have happened on the same day, would you have had this problem?

It's a pity you can't configure hooks, because it seems the best solution.

I hope be useful.

Best regards,
Rachel
Reply all
Reply to author
Forward
0 new messages