How to skip a build after a "git push" done by a Jenkinsfile

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to skip a build after a "git push" done by a Jenkinsfile

Idan Adar
Hi all,

In a declarative pipeline (a Jenkinsfile in the repo), how can I stop a job from getting re/triggered due to a push event in GitHub?
For example:

stage ("Publish to npm") {
   steps
{
      sh
'''
         npm publish
         npm --no-git-tag-version version minor
      '''

     
      sh
'''
         git commit -am '
Bumped version number'
         git push
      '''

   
}
}

The "git push" will trigger the push webhook in GitHub that makes a call to Jenkins, which will in turn start the same Jenkinsfile and again bump the version, commit, push and again... a loop.
How can we not-trigger the job in this scenario?


--
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/fcb1b9ad-c18b-487a-96ee-f7b13a447d02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

Idan Adar
I should add that the job is of multibranch type.

On Thursday, March 23, 2017 at 3:10:51 PM UTC+2, Idan Adar wrote:
Hi all,

In a declarative pipeline (a Jenkinsfile in the repo), how can I stop a job from getting re/triggered due to a push event in GitHub?
For example:

stage ("Publish to npm") {
   steps
{
      sh
'''
         npm publish
         npm --no-git-tag-version version minor
      '''

     
      sh
'''
         git commit -am '
Bumped version number'
         git push
      '''

   
}
}

The "git push" will trigger the push webhook in GitHub that makes a call to Jenkins, which will in turn start the same Jenkinsfile and again bump the version, commit, push and again... a loop.
How can we not-trigger the job in this scenario?


--
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/af0d3836-ae98-4e09-93bf-9dfa4d65b39f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

Mark Waite-2
The git plugin as used in pipeline doesn't support ignoring commits from certain users, or ignoring commits with certain messages.  Until it does, you will probably need to "short circuit" and exit from the pipeline after using git commands to extract the latest commit message from the repository.  It's not a pretty solution, but it can work now.

Another alternative is to fork the git plugin and add the "ignore commits from specific user" support to the pipeline.

Mark Waite

On Thu, Mar 23, 2017 at 7:43 AM Idan Adar <[hidden email]> wrote:
I should add that the job is of multibranch type.


On Thursday, March 23, 2017 at 3:10:51 PM UTC+2, Idan Adar wrote:
Hi all,

In a declarative pipeline (a Jenkinsfile in the repo), how can I stop a job from getting re/triggered due to a push event in GitHub?
For example:

stage ("Publish to npm") {
   steps
{
      sh
'''
         npm publish
         npm --no-git-tag-version version minor
      '''

     
      sh
'''
         git commit -am '
Bumped version number'
         git push
      '''

   
}
}

The "git push" will trigger the push webhook in GitHub that makes a call to Jenkins, which will in turn start the same Jenkinsfile and again bump the version, commit, push and again... a loop.
How can we not-trigger the job in this scenario?


--
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/af0d3836-ae98-4e09-93bf-9dfa4d65b39f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/CAO49JtHfc7jEz%2BoYG7sj3fQVuVq8BRrSeDyB1N1HwqKHD8E7Gg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

Idan Adar
Unfortunately I am not versed enough in programming to add this functionality... 

I think that the workaround will add lots of "red rows" in the job view, because it first has to checkout the repo, check the messages and then abort...

On Thursday, March 23, 2017 at 3:59:07 PM UTC+2, Mark Waite wrote:
The git plugin as used in pipeline doesn't support ignoring commits from certain users, or ignoring commits with certain messages.  Until it does, you will probably need to "short circuit" and exit from the pipeline after using git commands to extract the latest commit message from the repository.  It's not a pretty solution, but it can work now.

Another alternative is to fork the git plugin and add the "ignore commits from specific user" support to the pipeline.

Mark Waite

On Thu, Mar 23, 2017 at 7:43 AM Idan Adar <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="MGMH1W0RCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">id...@...> wrote:
I should add that the job is of multibranch type.


On Thursday, March 23, 2017 at 3:10:51 PM UTC+2, Idan Adar wrote:
Hi all,

In a declarative pipeline (a Jenkinsfile in the repo), how can I stop a job from getting re/triggered due to a push event in GitHub?
For example:

stage ("Publish to npm") {
   steps
{
      sh
'''
         npm publish
         npm --no-git-tag-version version minor
      '''

     
      sh
'''
         git commit -am '
Bumped version number'
         git push
      '''

   
}
}

The "git push" will trigger the push webhook in GitHub that makes a call to Jenkins, which will in turn start the same Jenkinsfile and again bump the version, commit, push and again... a loop.
How can we not-trigger the job in this scenario?


--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="MGMH1W0RCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/af0d3836-ae98-4e09-93bf-9dfa4d65b39f%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/af0d3836-ae98-4e09-93bf-9dfa4d65b39f%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/af0d3836-ae98-4e09-93bf-9dfa4d65b39f%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/af0d3836-ae98-4e09-93bf-9dfa4d65b39f%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
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/a8f94adf-357e-412e-8665-16c5663a1c05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

Idan Adar
Could it be that this is the solution? http://stackoverflow.com/questions/42798006/how-to-disable-automatic-build-from-scm-change-in-jenkinsfile
The flow in my case is:

PR to GHE > GHE sends pull_request webhook to Jenkins > Jenkins uses the Jenkinsfile to run unit tests > Jenkins makes a call to merge the PR to the master branch.
The merge to the master branch is essentially a push webhook, so: GHE sends a push webhook to Jenkins > Jenkins uses the same Jenkinsfile to run again unit tests > there is logic to not-merge in case the branch is the master branch > Instead publish to npm > bump the version number > commit & push to git.

This time because the the whole thing worked from a checkout of the master branch and not based on a PR, the option to "Suppress automatic SCM triggering" should hopefully stop the loop from starting...

On Thursday, March 23, 2017 at 4:09:09 PM UTC+2, Idan Adar wrote:
Unfortunately I am not versed enough in programming to add this functionality... 

I think that the workaround will add lots of "red rows" in the job view, because it first has to checkout the repo, check the messages and then abort...

On Thursday, March 23, 2017 at 3:59:07 PM UTC+2, Mark Waite wrote:
The git plugin as used in pipeline doesn't support ignoring commits from certain users, or ignoring commits with certain messages.  Until it does, you will probably need to "short circuit" and exit from the pipeline after using git commands to extract the latest commit message from the repository.  It's not a pretty solution, but it can work now.

Another alternative is to fork the git plugin and add the "ignore commits from specific user" support to the pipeline.

Mark Waite

On Thu, Mar 23, 2017 at 7:43 AM Idan Adar <[hidden email]> wrote:
I should add that the job is of multibranch type.


On Thursday, March 23, 2017 at 3:10:51 PM UTC+2, Idan Adar wrote:
Hi all,

In a declarative pipeline (a Jenkinsfile in the repo), how can I stop a job from getting re/triggered due to a push event in GitHub?
For example:

stage ("Publish to npm") {
   steps
{
      sh
'''
         npm publish
         npm --no-git-tag-version version minor
      '''

     
      sh
'''
         git commit -am '
Bumped version number'
         git push
      '''

   
}
}

The "git push" will trigger the push webhook in GitHub that makes a call to Jenkins, which will in turn start the same Jenkinsfile and again bump the version, commit, push and again... a loop.
How can we not-trigger the job in this scenario?


--
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 jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/af0d3836-ae98-4e09-93bf-9dfa4d65b39f%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/af0d3836-ae98-4e09-93bf-9dfa4d65b39f%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/af0d3836-ae98-4e09-93bf-9dfa4d65b39f%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/af0d3836-ae98-4e09-93bf-9dfa4d65b39f%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
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/2eb19e36-0fee-45e8-b347-a11f3ff64577%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

Idan Adar
The above is not the solution. It simply makes the job not run...

--
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/a05675f3-4374-4207-8db6-f9874ad2428c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

Idan Adar
This answer is promising: http://stackoverflow.com/a/41164841/1530814

The problem is that when using Branch Source as Git (so that these options are available in the Jenkins UI, $CHANGE_ID is not available... (my code depends on it).
When using Branch Source as GitHub, these options are not available...

--
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/5ee93b0d-3dfe-4cdf-9b5b-c52bdb1568a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

Idan Adar
As Mark mentioned, the alternative is to trigger an exception... (which will in turn show the row in red color).
I do it as follows. After checking out, if a git commit includes "[ci skip]" I use a "success" keyword (this keyword does not exit) hence the build stops.

I would love for this keyword to exist, so that the job will stop with a green row instead of a red row... Is this possible?

stage ("Checkout SCM") {
    steps
{
        script
{
           STAGE_NAME
= "Checkout SCM"
               
           checkout scm
           result
= sh (script: "git log -1 | grep '.*\\[ci skip\\].*'", returnStatus: true)
           
if (result == 0) {
              echo
("'ci skip' spotted in git commit. Aborting.")
              success
("'ci skip' spotted in git commit. Aborting.")
           
}
       
}
   
}
}

--
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/cd25bb36-d893-4281-a04e-d5a6bb54f6b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

stephenconnolly
Skipping polling from the git plugin is not an option for branch sources

The branch source tracks last revision built for each branch and fires a build of the current revision is not equal to the last.

What you want is a build step that stops the build with an "ignore" status of some sort.

On Sat 25 Mar 2017 at 09:52, Idan Adar <[hidden email]> wrote:
As Mark mentioned, the alternative is to trigger an exception... (which will in turn show the row in red color).
I do it as follows. After checking out, if a git commit includes "[ci skip]" I use a "success" keyword (this keyword does not exit) hence the build stops.

I would love for this keyword to exist, so that the job will stop with a green row instead of a red row... Is this possible?

stage ("Checkout SCM") {
    steps
{
        script
{
           STAGE_NAME
= "Checkout SCM"
               
           checkout scm
           result
= sh (script: "git log -1 | grep '.*\\[ci skip\\].*'", returnStatus: true)
           
if (result == 0) {
              echo
("'ci skip' spotted in git commit. Aborting.")
              success
("'ci skip' spotted in git commit. Aborting.")
           
}
       
}
   
}
}

--
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/cd25bb36-d893-4281-a04e-d5a6bb54f6b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Sent from my phone

--
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/CA%2BnPnMymwUSu6%2BDiUQpgwZdVwZ4t%3DQP81DggRo6iwMX%3Dr_CWSA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

Idan Adar
Thus far I have tried:

* success ("...") -- build stops with "failed" status
* sh "exit 0" -- build doesn't stop (continues to the next stage in the pipeline)

I think "exit 0" is the way to go, but didn't yet figure out exactly how... 

On Saturday, March 25, 2017 at 1:01:15 PM UTC+3, Stephen Connolly wrote:
Skipping polling from the git plugin is not an option for branch sources

The branch source tracks last revision built for each branch and fires a build of the current revision is not equal to the last.

What you want is a build step that stops the build with an "ignore" status of some sort.

On Sat 25 Mar 2017 at 09:52, Idan Adar <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="SrTYJpyhCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">id...@...> wrote:
As Mark mentioned, the alternative is to trigger an exception... (which will in turn show the row in red color).
I do it as follows. After checking out, if a git commit includes "[ci skip]" I use a "success" keyword (this keyword does not exit) hence the build stops.

I would love for this keyword to exist, so that the job will stop with a green row instead of a red row... Is this possible?

stage ("Checkout SCM") {
    steps
{
        script
{
           STAGE_NAME
= "Checkout SCM"
               
           checkout scm
           result
= sh (script: "git log -1 | grep '.*\\[ci skip\\].*'", returnStatus: true)
           
if (result == 0) {
              echo
("'ci skip' spotted in git commit. Aborting.")
              success
("'ci skip' spotted in git commit. Aborting.")
           
}
       
}
   
}
}

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="SrTYJpyhCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/cd25bb36-d893-4281-a04e-d5a6bb54f6b8%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/cd25bb36-d893-4281-a04e-d5a6bb54f6b8%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/cd25bb36-d893-4281-a04e-d5a6bb54f6b8%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/cd25bb36-d893-4281-a04e-d5a6bb54f6b8%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.
--
Sent from my phone

--
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/720a5799-1150-462a-afe8-55d3e01636ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

Idan Adar
I am now attempting to solve this use the environment, when and expression blocks.
Could some please take a look? http://stackoverflow.com/questions/43016942/can-a-jenkins-job-be-aborted-with-success-result

--
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/3c884828-05c1-4038-8864-e0e5fae9e727%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

Idan Adar
At last, resolved using parameters, when and expression blocks.
See here: http://stackoverflow.com/questions/43016942/can-a-jenkins-job-be-aborted-with-success-result

--
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/fe5bcea7-305e-45b2-b9e1-750bc243574b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to skip a build after a "git push" done by a Jenkinsfile

jimmychan
This post has NOT been accepted by the mailing list yet.
Do you mind sharing your full solution?
Loading...