Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-43353

Ability to abort all previous running builds

    Details

    • Similar Issues:

      Description

      It is sometimes desirable for a job (such as a branch project) to simply abort any previously running builds as soon as a new build starts. For example, in a branch project for a pull request, you might want to see test results from an earlier commit even after pushing follow-up commits, but most of the time you only care about the results of the PR head, and computer time might be too valuable to waste on the older ones.

      (I think gerrit-trigger does something like this automatically, and I have seen Alex Gray invent the same kind of pattern with JenkinsPy.)

      Merely setting the job to not be concurrent-capable does not suffice, since then newer builds will queue up waiting for the older ones to finish.


      Manual equivalent courtesy of Brandon Squizzato:

      def buildNumber = BUILD_NUMBER as int; if (buildNumber > 1) milestone(buildNumber - 1); milestone(buildNumber)
      

        Attachments

          Issue Links

            Activity

            Hide
            kmagomedov Kamil Magomedov added a comment -

            Brandon Squizzato Not sure how your solution is supposed to work after the first build. Each subsequent build will create two milestones and pass them immediately. First build is the only one that will be aborted.

            Show
            kmagomedov Kamil Magomedov added a comment - Brandon Squizzato Not sure how your solution is supposed to work after the first build. Each subsequent build will create two milestones and pass them immediately. First build is the only one that will be aborted.
            Hide
            bsquizz Brandon Squizzato added a comment -

            Kamil Magomedov

            Build #1 would define milestone(1)
            Build #2 would define milestone(1) and milestone(2)
            Build #3 would define milestone(2) and milestone(3)
            Build #4 would define milestone(3) and milestone(4)

            and so on ...

            Every time a build runs, it is passing the highest milestone of the previous build. This causes the previous build to abort. From https://jenkins.io/doc/pipeline/steps/pipeline-milestone-step/

            > The milestone step forces all builds to go through in order, so an older build will never be allowed pass a milestone (it is aborted) if a newer build already passed it. 

            Show
            bsquizz Brandon Squizzato added a comment - Kamil Magomedov Build #1 would define milestone(1) Build #2 would define milestone(1) and milestone(2) Build #3 would define milestone(2) and milestone(3) Build #4 would define milestone(3) and milestone(4) and so on ... Every time a build runs, it is passing the highest milestone of the previous build. This causes the previous build to abort. From https://jenkins.io/doc/pipeline/steps/pipeline-milestone-step/ – > The milestone step forces all builds to go through in order, so an older build will never be allowed pass a milestone (it is aborted) if a newer build already passed it. 
            Hide
            kmagomedov Kamil Magomedov added a comment - - edited

            Brandon Squizzato ah, I apologize, I had the wrong idea about the way milestone works. I thought that for the older builds to be aborted the newest build has to pass at least one more milestone step. So three milestone steps for Build #3 and so on. That's how I always used it. Good to know that there's the other way, thank you!

            Show
            kmagomedov Kamil Magomedov added a comment - - edited Brandon Squizzato ah, I apologize, I had the wrong idea about the way milestone works. I thought that for the older builds to be aborted the newest build has to pass at least one more milestone step. So three milestone steps for Build #3 and so on. That's how I always used it. Good to know that there's the other way, thank you!
            Hide
            lkraider Paul Eipper added a comment -

            How to use the milestone solution in a declarative pipeline ? Brandon Squizzato Do you have a sample Jenkinsfile doing this?

            Show
            lkraider Paul Eipper added a comment - How to use the milestone solution in a declarative pipeline ? Brandon Squizzato Do you have a sample Jenkinsfile doing this?
            Show
            stchar Stanislav Ovchar added a comment - Created PR  https://github.com/jenkinsci/pipeline-milestone-step-plugin/pull/18

              People

              • Assignee:
                amuniz Antonio Muñiz
                Reporter:
                jglick Jesse Glick
              • Votes:
                20 Vote for this issue
                Watchers:
                29 Start watching this issue

                Dates

                • Created:
                  Updated: