简体   繁体   中英

Running parallel jobs in Jenkins

I'm using Jenkins for my builds, and I wrote some test scripts that I need to run after the compilation of the build. I want to save some time, so I have to run the test scripts parallel. How can I do that?

EDIT: ok, I understand know that I need a separate Job for each test (for 4 tests I need 4 jobs, right?) So, I did that, and via the parent job I ran this jobs. (using "build other projects" plugin). But I didn't managed to aggregate the results (using aggregate downstream test results). The parent job exits before the downstream jobs were finished. What shall I do?

Thanks.

You can use multi-job plugin. This would allow you to run multiple jobs in parallel and the parent job would wait for the sub jobs to be completed. The parent jobs status can be determined by the sub jobs status.

https://wiki.jenkins-ci.org/display/JENKINS/Multijob+Plugin

Jenkins doesn't really allow you to run things in parallel. You can however split your build into different jobs to achieve this. It would look like this.

  • Job to compile the source runs.
  • Jobs that run the tests are triggered by the completion of the compilation and start running. They copy compilation results from the previous job into their workspaces.

This is a big kludgy though. The better alternative would be to parallelise within the scripts that run the tests, ie you run a single script and this then runs the tests in parallel. If this is not possible, you'll have to split into different jobs though.

Have you looked at the Jenkins JOIN Plugin? I have not used it but I believe it is what you are attempting to accomplish.

- Mike

Actually you can but you will need some coding behind. In my case, I have parallel test execution on jenkins.

1) Create a small job with parameters that is supposed to do a test run with a small suite

2) Edit this job to run on a list of slaves (where you have the proper environment)

3) Edit this build to allow concurrent builds

And now the hard part.

4) Create a small java program for computing the list of parameters for each job to run.

5) Iterate trough the list and launch a new Jenkins job on a new thread.

Put a Thread.sleep(5000) between runs in order to avoid communication errors

6) Join the threads

At the end of each job, I send the results to a shared location in order to perform some reporting at the end of all tests.

For starting a jenkins job with parameters use CLI

I intend to make my code as generic as possible and publish it if anyone else will need it.

You can use https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin with code like this

parallel (

// job 1, 2 and 3 will be scheduled in parallel.
{ build("job1") },
{ build("job2") },
{ build("job3") }

)

You can use any one of the followings:

  1. Multijob plugin

  2. Build Flow plugin

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