Trigger new build only for the latest git tag

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Trigger new build only for the latest git tag

Alex Domoradov
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://[hidden email]: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://[hidden email]: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://[hidden email]: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

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/72f3e6ee-1ef1-477b-ba74-5ce056b35c6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trigger new build only for the latest git tag

constellate9
bump. i am running into a similar issue. any resolution?

On Sunday, September 4, 2016 at 9:26:10 AM UTC-7, Alex Domoradov wrote:
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://[hidden email]: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://[hidden email]: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://[hidden email]: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

<a href="http://erics-notes.blogspot.com/2013/05/jenkins-build-latest-git-tag.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ferics-notes.blogspot.com%2F2013%2F05%2Fjenkins-build-latest-git-tag.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH8BDCENy6jhNCx1cMClfqq3QIQIg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ferics-notes.blogspot.com%2F2013%2F05%2Fjenkins-build-latest-git-tag.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH8BDCENy6jhNCx1cMClfqq3QIQIg&#39;;return true;">http://erics-notes.blogspot.com/2013/05/jenkins-build-latest-git-tag.html
<a href="http://www.cyber-tec.org/2015/09/20/build-last-git-tag-with-jenkins/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.cyber-tec.org%2F2015%2F09%2F20%2Fbuild-last-git-tag-with-jenkins%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH7sGK_kDefwC2XnoUFiJ33RmWccA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.cyber-tec.org%2F2015%2F09%2F20%2Fbuild-last-git-tag-with-jenkins%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH7sGK_kDefwC2XnoUFiJ33RmWccA&#39;;return true;">http://www.cyber-tec.org/2015/09/20/build-last-git-tag-with-jenkins/

but can't find any suitable solution

Thanks in advance

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/815796ef-b941-49d6-b33a-56acb662df46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Trigger new build only for the latest git tag

Rachel Moreno
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

El miércoles, 19 de octubre de 2016, 3:35:41 (UTC+2), [hidden email] escribió:
bump. i am running into a similar issue. any resolution?

On Sunday, September 4, 2016 at 9:26:10 AM UTC-7, Alex Domoradov wrote:
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://[hidden email]: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://[hidden email]: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://[hidden email]: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

<a href="http://erics-notes.blogspot.com/2013/05/jenkins-build-latest-git-tag.html" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ferics-notes.blogspot.com%2F2013%2F05%2Fjenkins-build-latest-git-tag.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH8BDCENy6jhNCx1cMClfqq3QIQIg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ferics-notes.blogspot.com%2F2013%2F05%2Fjenkins-build-latest-git-tag.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH8BDCENy6jhNCx1cMClfqq3QIQIg&#39;;return true;">http://erics-notes.blogspot.com/2013/05/jenkins-build-latest-git-tag.html
<a href="http://www.cyber-tec.org/2015/09/20/build-last-git-tag-with-jenkins/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.cyber-tec.org%2F2015%2F09%2F20%2Fbuild-last-git-tag-with-jenkins%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH7sGK_kDefwC2XnoUFiJ33RmWccA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.cyber-tec.org%2F2015%2F09%2F20%2Fbuild-last-git-tag-with-jenkins%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH7sGK_kDefwC2XnoUFiJ33RmWccA&#39;;return true;">http://www.cyber-tec.org/2015/09/20/build-last-git-tag-with-jenkins/

but can't find any suitable solution

Thanks in advance

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/40c4149d-efa8-4468-9fcc-a96de599311b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.