I have a job in Jenkins which triggers another one.
How do I make the job abort if the triggered one fails?
Thanks
Gil
You can open http://$HOST/jenkins/job/$PROJECT/$BUILD/stop
Use parametrized trigger plugin from here.
Use it as a build step ("Trigger/call builds on other projects"), check "Block until the triggered projects finish their builds" box, and choose "Fail this build step if the triggered build is worse or equal to FAILURE".
You can add the post build task to the triggered job that will:
run if Finished: FAILURE found in the build log,
execute shell:
curl "$UPSTREAM_BUILD/stop" >/dev/null
$UPSTREAM_BUILD neds to be specified by parameter or you can determine it somehow using API...
I am currently setting up my matrix builds to abort all other configurations if one failed and it works as above.
Related
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?
use Post Build Task plugin for conditional steps
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:
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).
You will see Execute script after a failed build. being displayed on console output when the job fails.
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.
I have a groovy script to cancel a running job (behaves similar to "cancel" in the jenkins gui). I want to abort build in a way that nothing to be executed afterwards.
Using build.doStop() I am able to abort the build steps but aborting the build does not stop executing the post build actions. Is there any way that we can abort the postbuild action as well?
I appreciate any help or suggestions, thanks
Maybe it's a late reply, but better ever than never
Try adding a Groovy Postbuild or Execute a set of scripts (and then in Build Steps select Execute System Groovy Script) as a first post build action. You can use either method, stop() or interrupt().
Nevertheless, the build always finishes as failed (couldn't figure out why).
Tested on Jenkins 2.73.1
How can I stop a build of specific job according to it's Parameter
for example:
I run the job FooJob multiple times with different FooParam with the following url:
http://10.10.10.10:8080/job/FooJob/buildWithParameters?FooParam=15
http://10.10.10.10:8080/job/FooJob/buildWithParameters?FooParam=19
http://10.10.10.10:8080/job/FooJob/buildWithParameters?FooParam=24
I am looking for url that can stop FooJob that has FooParam=19 if it's running
So I though if getting all the running builds of the job and check if it has the parameter FooParam=19 than to stop it
How can i do that?
Based on the platform (linux,window, other platforms). select build step within your Jenkins job .Execute shell or execute windows batch script. Just check parameter using simple "if condition" .If fooparam ==19 then stop your build by using "exit 0" (success) or "exit 1" (fail).
In the interest of reducing build times I would like to only clean down the Jenkins job workspace if a build fails. Is there of doing this using post build action? Does Jenkins set a variable to the effect of 'BUILD FAILED' that can be read in a script that could be use in the post build action section of the job config?
Thanks in advance.
Post-build Task plugin can read your console output and execute scripts if regex is found. When a build step fails, it will print "BUILD FAILED" into console output.
Configure post-build task to look for that, and execute the cleanup in that case.
Workspace Cleanup Plugin has an option just for that. Add its post build step, tick particular checkbox and it will clean only failed (unstable?) builds.
I have a job that is running unit tests on a project build and then ssh into a staging server and pulling down from the master branch. Right now I'm using the post-build-script but this is running regardless of pass/fail. I'm trying to use the parameterized build plugin to trigger a new job when the build is passed. So far I've created the new job and set to trigger in the configuration of the original.
The new job is building ok on its own but the original job isn't triggering it. From 'Add post-build action' I've selected 'Trigger parameterized build on other projects' with build triggers:
Projects to build: new_job, Trigger when build is: Stable or unstable but not failed.
Any ideas appreciated!
C
If you don't actually need to pass a parameter to the second build, make sure that "Trigger build without parameters" is checked in the parameterized build trigger options.
The "Post build task" allows you to query the console log of the build step, and is executed only when criteria is met.
Jenkins writes BUILD SUCCESSFUL in the console log for every build step that had passed.
In your "Post build task" step, under Log text just put BUILD SUCCESSFUL, and under Script put your linux script/commands.
This way your script/commands will only be executed if the Build Step was successful