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

Cancel existing job if the new job is pending

    XMLWordPrintable

Details

    Description

      Pushing the code and triggering new job will not abort the previous one, making the user wait for the results of the previous job before the new one is performed. It would be nice if there was an option to abort the existing job and immediately start running the new one.

       

      Here's the similar issue reported against github-organization-folder-plugin: https://issues.jenkins-ci.org/browse/JENKINS-38409

       

      Here's the issue in the old Github Pull request builder plugin where it was implemented: https://github.com/jenkinsci/ghprb-plugin/issues/241

      Attachments

        Issue Links

          Activity

            nemanjaboric Nemanja Boric created issue -
            nemanjaboric Nemanja Boric made changes -
            Field Original Value New Value
            Description If `disableConcurrentBuilds` is enabled for a job, pushing the code and triggering new
            job will not abort the previous one, making the user wait for the results of the previous job
            before the new one is performed. It would be nice if there was an option to abort the existing
            job and immediately start running the new one.
            If `disableConcurrentBuilds` is enabled for a job, pushing the code and triggering new
             job will not abort the previous one, making the user wait for the results of the previous job
             before the new one is performed. It would be nice if there was an option to abort the existing
             job and immediately start running the new one.

             

            Here's the similar issue reported against github-organization-folder-plugin: https://issues.jenkins-ci.org/browse/JENKINS-38409
            nemanjaboric Nemanja Boric made changes -
            Description If `disableConcurrentBuilds` is enabled for a job, pushing the code and triggering new
             job will not abort the previous one, making the user wait for the results of the previous job
             before the new one is performed. It would be nice if there was an option to abort the existing
             job and immediately start running the new one.

             

            Here's the similar issue reported against github-organization-folder-plugin: https://issues.jenkins-ci.org/browse/JENKINS-38409
            Pushing the code and triggering new job will not abort the previous one, making the user wait for the results of the previous job before the new one is performed. It would be nice if there was an option to abort the existing job and immediately start running the new one.

             

            Here's the similar issue reported against github-organization-folder-plugin: https://issues.jenkins-ci.org/browse/JENKINS-38409
            nemanjaboric Nemanja Boric made changes -
            Component/s github-branch-source-plugin [ 20858 ]
            Component/s workflow-job-plugin [ 21716 ]
            nemanjaboric Nemanja Boric made changes -
            Description Pushing the code and triggering new job will not abort the previous one, making the user wait for the results of the previous job before the new one is performed. It would be nice if there was an option to abort the existing job and immediately start running the new one.

             

            Here's the similar issue reported against github-organization-folder-plugin: https://issues.jenkins-ci.org/browse/JENKINS-38409
            Pushing the code and triggering new job will not abort the previous one, making the user wait for the results of the previous job before the new one is performed. It would be nice if there was an option to abort the existing job and immediately start running the new one.

             

            Here's the similar issue reported against github-organization-folder-plugin: https://issues.jenkins-ci.org/browse/JENKINS-38409

             

            Here's the issue in the old Github Pull request builder plugin where it was implemented: https://github.com/jenkinsci/ghprb-plugin/issues/241
            bksaville Brian Saville added a comment -

            You can use the milestone step to accomplish this - this is what we're doing for PR builds.

            bksaville Brian Saville added a comment - You can use the milestone step to accomplish this - this is what we're doing for PR builds.

            You can use workaround:

            killall_jobs()

            @NonCPS
            def killall_jobs() {
            def jobname = env.JOB_NAME
            def buildnum = env.BUILD_NUMBER.toInteger()

            def job = Jenkins.instance.getItemByFullName(jobname)
            for (build in job.builds) {
            if (!build.isBuilding())

            { continue; }

            if (buildnum == build.getNumber().toInteger())

            { continue; println "equals" }

            echo "Kill task = ${build}"
            build.doStop();
            }
            }

            dubrsl Viacheslav Dubrovskyi added a comment - You can use workaround: killall_jobs() @NonCPS def killall_jobs() { def jobname = env.JOB_NAME def buildnum = env.BUILD_NUMBER.toInteger() def job = Jenkins.instance.getItemByFullName(jobname) for (build in job.builds) { if (!build.isBuilding()) { continue; } if (buildnum == build.getNumber().toInteger()) { continue; println "equals" } echo "Kill task = ${build}" build.doStop(); } }

            I was trying to use this workaround, but it doesn't seem to be suitable for my use case, as I use declarative pipeline and a "dockerfile agent". So I think the whole docker image will be built (which is one of the most time consuming parts of the job) before the killall_jobs() function can be used.

            lucasocio Leandro Lucarella added a comment - I was trying to use this workaround, but it doesn't seem to be suitable for my use case, as I use declarative pipeline and a "dockerfile agent". So I think the whole docker image will be built (which is one of the most time consuming parts of the job) before the killall_jobs() function can be used.
            lucasocio Leandro Lucarella made changes -
            Priority Minor [ 4 ] Major [ 3 ]

            I raised the priority to Major (I wish there was a severity field, as I can't handle the priorities really), but for us, having dozens of projects that build several PRs concurrently, not having a way to abort useless builds is making the jenkins server stop being practical.

            lucasocio Leandro Lucarella added a comment - I raised the priority to Major (I wish there was a severity field, as I can't handle the priorities really), but for us, having dozens of projects that build several PRs concurrently, not having a way to abort useless builds is making the jenkins server stop being practical.
            rtyler R. Tyler Croy made changes -
            Link This issue relates to JENKINS-38409 [ JENKINS-38409 ]
            nickbrown Nicholas Brown made changes -
            Link This issue is related to JENKINS-47503 [ JENKINS-47503 ]
            nickbrown Nicholas Brown made changes -
            Component/s workflow-multibranch-plugin [ 21465 ]
            nickbrown Nicholas Brown made changes -
            Labels multi-branch
            nickbrown Nicholas Brown made changes -
            Link This issue is related to JENKINS-43353 [ JENKINS-43353 ]
            jglick Jesse Glick added a comment -

            Duplicate of JENKINS-43353.

            jglick Jesse Glick added a comment - Duplicate of JENKINS-43353 .
            jglick Jesse Glick made changes -
            Resolution Duplicate [ 3 ]
            Status Open [ 1 ] Resolved [ 5 ]

            People

              Unassigned Unassigned
              nemanjaboric Nemanja Boric
              Votes:
              12 Vote for this issue
              Watchers:
              13 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: