Groovy script to abort current build and skip other action of the job

6,431 views
Skip to first unread message

dthomas

unread,
Oct 24, 2012, 2:24:10 PM10/24/12
to jenkins...@googlegroups.com
I have a job which is pretty resource intensive.
That's why i want it to be executed only when all upstream jobs are stable.

Therefore I prepended a groovy script action to the job (original action now #2).
The groovy script checks that all upstream jobs are stable.
But I am unable to stop the build from groovy so that:
- the job is marked as "aborted" (not failed)
AND
- the following actions in that job are not executed

I am able to set the result of the build with:
  build = Thread.currentThread().executable
  build.setResult(Result.ABORTED)
But this would obviously continue the build and execute the following actions.

Both of the following will mark the build as failed and will also process all action:
  build.getExecutor().interrupt()
  build.getExecutor().interrupt(Result.ABORTED)

Any hint how to abort the job after the first action / groovy script without executing the following actions AND marking the job as ABORTED?

Thanks,
Dirk

dthomas

unread,
Nov 5, 2012, 1:51:07 AM11/5/12
to jenkins...@googlegroups.com
bump :-)

Since the user can trigger that kind of command via the UI there should be some corresponding API for that, right?
I only found methods with Stapler request and response objects as parameters - but I should rather not pass fake arguments I guess.

Can somebody confirm that no corresponding API exists currently?
Than I would fill an enhancement request to add that kind of method to the a build.

- Dirk
Message has been deleted

Dirk Thomas

unread,
Nov 8, 2012, 3:48:58 AM11/8/12
to jenkins...@googlegroups.com
As mentioned in my original post both of the following will mark the build as failed (not aborted) and will also process all further build actions:
build.getExecutor().interrupt()
build.getExecutor().interrupt(Result.ABORTED)

Especially that the second line marks the build as failed I would call broken.

- Dirk


On 08.11.2012 00:40, AdvanTiSS wrote:
> build.getExecutor().interrupt();

AdvanTiSS

unread,
Nov 8, 2012, 4:35:51 AM11/8/12
to jenkins...@googlegroups.com
"Since the user can trigger that kind of command via the UI there should be some corresponding API for that, right?"

Stopping via UI executes the same [build.getExecutor().interrupt()], so you may have same problems with aborting builds from UI. 
Also, want notice that after upgrading from 1.477 to 1.487 we get some problems with downstream builds aborting - jenkins lost ability to abort them from UI.

Dirk Thomas

unread,
Nov 8, 2012, 4:16:03 PM11/8/12
to jenkins...@googlegroups.com
I am running 1.488 and can abort builds via UI.

But invoking the following function in a groovy script:
build.getExecutor().interrupt(Result.ABORTED)
does not cancel the build but run in to the end (including all following build actions) and marks the build as FAILED.

- Dirk

Dirk Thomas

unread,
Nov 9, 2012, 10:41:03 PM11/9/12
to jenkins...@googlegroups.com
After reading a bit in the Jenkins sources I found a work around which works for me:
throw new InterruptedException()
marks the build as ABORTED and does not process any further build actions.

Anyway I filled a bug report for the non-working Executor.interrupt() method:
https://issues.jenkins-ci.org/browse/JENKINS-15748

- Dirk
Reply all
Reply to author
Forward
0 new messages