Continuous Execution in Jenkins

1.6k views Asked by At

How to execute the same build again and again in Jenkins(Say I want to execute the build for 10 times continuously). After each execution the reports have to copied.

Don't say create 10 jobs and make use of Downstream/Upstream.

4

There are 4 answers

1
LucasF On BEST ANSWER

We do this with this Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin

With this plugin "Build Flow Plugin" you can create a new job type in Jenkins called "Build Flow" which allows you to control a build pipeline aka flow by groovy script:

for ( n in 0..30 ) {
        build("Your Jenkins Job", SampleParameter: "Value")
}

This will run the Jenkins Job "Your Jenkins Job" 30 times.

1
NotAgain On

It is possible to launch jobs via script. Create a wrapper job which will invoke the given job.

This is how you launch a job via command line (I use Windows)

java -jar <Jenkins Install folder>\war\WEB-INF\jenkins-cli.jar -s http://JenkinsServer:8888/ build DEMO -s  --username ChuckNorris --password HellYeah 

There are variations where you need not put username and password. Google is your friend.

So i will write a wrapper job which will call this job. I will use "Execute Windows Batch Command" as the build step and then write a simple loop in which it will invoke the job 10 times.

NOTE: The -s after the invoked job name. That makes the master wait for the job to complete before launching the next iteration of the same job. You might want to keep this unless 10 same jobs simultaneously running is fine with you.

1
carlo.bongiovanni On

You can use the method given from NotAgain, or a curl request like this.

If you don't want to create a wrapper, you can add to your jenkins installation the Throttle concurrent builds plugin, because you may want that your job has exclusive access to its workspace (depending on what you do, it could fail or not).

Finally the last possibility is to create another job, and add as a post-build action the option to build other jobs, as many time as you want (yes it's weird but it can works, according to what you need to do).

0
Djordje Stefanovic On

You can use pretty simple solution by using Build Periodically, from Build Triggers, such as:

H/15 * * * *

This triggers job in every fifteen minutes (perhaps at :07, :22, :37, :52). So, this will not trigger the next execution immediately, but you can schedule it in this way.