Jenkins stop a build of specific job according to Parameter - jenkins

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).

Related

How to trigger parametrized Jenkins Job using command line?

Recently, we have implemented a parametrized Jenkins Pipeline Job to trigger our Selenium TestCases. We want to trigger the build using CLI (in our case 'Command Prompt'). But unfortunately we are unable to send any parameter values using CLI. The Job is getting triggered with default values only.
We tried below way but job is getting trigger always with first test case (default value) in the TestCase choice dropdown:
curl -I https://<jenkinsURL>/job/<jobName>/buildWithParameters?token=<tokenName>&TestCase=<TCName>
where,
TestCase is Choice Parameter to select a desired test case to execute.
Anybody is having any idea, please help me out.
Thanks in advance...!!

Need to run a command if the jenkins build stuck

In the Jenkins "Abort the build if it's stuck" feature, if a time out happens I want to run a powershell command, instead of aborting or failing the build. Is it possible to accomplish this?
under system configuration-> configure system, found below option:
once enabled this option, "perform build step option" will be available under "time-out action" where we can execute any script or cmd.
Perhaps you could set a "Time-out variable" in the "Abort the build..." menu. Then run a post-build script using the PostBuildScript plugin that checks that env var and takes action accordingly. Haven't tried it.

How can I add a Jenkins post action to execute two different scripts once the build successed or failed exclusively?

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.

how to run multiple builds on a single Job in jenkins

I have a script to run to which i give multiple parameters in a loop, it takes each parameter completes the cycle and then the next one.
I need to run this on Jenkins, is there any option that i can run multiple builds on a single job ? I mean each parameter should be a single build and all the builds should run in queue not parallel.
We have two options :
1.) In my case i use a shell script and csv file as an input to it. So i wrote a simple groovy script for getting the inputs from csv file. Then i used parameterized plugin to run the script
2.) In case if you want to see the workflow on GUI you can go for pipeline

How to abort Jenkins job if a triggered build failes

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.

Resources