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


On 08.11.2012 13:16, Dirk Thomas wrote:
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


On 08.11.2012 01:35, AdvanTiSS wrote:
"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.

On Thursday, November 8, 2012 10:49:08 AM UTC+2, dthomas wrote:

    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();
     >
     > On Monday, November 5, 2012 8:51:07 AM UTC+2, dthomas wrote:
     >
     >     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
     >
     >
     >     On Wednesday, October 24, 2012 11:24:10 AM UTC-7, dthomas wrote:
     >
     >         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
     >



Reply via email to