0

I want to execute a shell scripts if the Jenkins job build successful or another scripts if the Jenkins job build failed.

I added the post build task plugin, but it seems only can execute a shell in all status or just successful status, cannot specify another shell script to be run once build failed, the two scripts should be run exclusively.

are there anyone can help me on this?

user1744416
  • 171
  • 1
  • 12

2 Answers2

0

use Post Build Task plugin for conditional steps

yorammi
  • 6,272
  • 1
  • 28
  • 34
  • There is conditional steps, it only contain "AND" and "OR" operator, I think I need a "NOT" operation. the build can print a success message in the log or won't if failed, so I can easily add the script to run under success status, but how can I add the scripts to run under the failed status as there is not "NOT" operator. – user1744416 Apr 28 '17 at 06:44
  • If build fails it outputs BUILD FAILED so you can look for it – yorammi Apr 28 '17 at 06:51
0

I use Conditional BuildStep Plugin and Text Finder Run Condition Plugin to execute steps when the build fails.

But there's a limitation with this method: You have to find a text that is displayed ONLY when your build fails.

See the pictures below:

enter image description here

I add exit 0 at the end of the script to force the build to be successful so that the program can execute the next step, which is Conditional steps(multiple).

enter image description here

You will see Execute script after a failed build. being displayed on console output when the job fails.

enter image description here

This is the execution result.

You will also need to find a text that is displayed ONLY when the first step succeeds so that you can trigger another script.

Brian
  • 12,145
  • 20
  • 90
  • 153