简体   繁体   中英

How can I use Groovy Postbuild to force a job to success?

I am trying to force a unit test job to success if the main build returned a failed exit code. Here is how I configured it and it is not working (see screenshot). Does anyone know any reason why this shouldn't work? In this example I just want to show that a failing job can be changed to a passing job by a groovy postbuild step. The plugin doc implies that this should work.

  1. The main build runs a batch script with "EXIT 1" to fail the build.
  2. A Groovy Postbuild step runs manager.buildSuccess() in an attempt to force the build to success (but it fails to do so with no error).

我的截图

I found a discussion about that problem on jenkins-JIRA .

As a workaround it is proposed to use reflection to make the build successful:

manager.build.@result = hudson.model.Result.SUCCESS

This workaround doesn't work for me, but perhaps it can help you

Install Groovy Post Build Plug in. Then add the below Groovy Script.

manager.build.@result = hudson.model.Result.SUCCESS

Uncheck the Use Groovy Sandbox. This worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM