How to abort a job during it's execution by itself

17 views
Skip to first unread message

iostrym

unread,
Apr 11, 2018, 6:33:14 AM4/11/18
to Jenkins Users
Is there a possibility to abort a job during it's execution by the job itself.

For instance the job launch a script that do the update from versioning tool and if no update are available, then the job is aborted.
This way the job is not stored at all by Jenkins.

Some plugin do already the tool versioning scrutation but we can't use them for our specific tool versioning version.

This is why I'm looking for a smart way to abort a build.

Viacheslav Dubrovskyi

unread,
Sep 13, 2018, 9:44:51 AM9/13/18
to jenkins...@googlegroups.com
Hi

You can use this function for pipeline

@NonCPS
def killthis_job() {
  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" }
    currentBuild.result = 'ABORTED'
    error("Old build ${build} working.")
  }
}


11.04.2018 13:33, iostrym пишет:
--
WBD,
Viacheslav Dubrovskyi


Reply all
Reply to author
Forward
0 new messages