简体   繁体   English

在詹金斯运行并行作业

[英]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. 我将Jenkins用于构建,并编写了一些在构建编译后需要运行的测试脚本。 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. 编辑:好的,我知道我为每个测试需要一个单独的工作(对于4个测试,我需要4个工作,对吗?)所以,我做到了,并通过上级工作运行了这个工作。 (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 https://wiki.jenkins-ci.org/display/JENKINS/Multijob+Plugin

Jenkins doesn't really allow you to run things in parallel. 詹金斯(Jenkins)确实不允许您并行运行事物。 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? 您是否看过Jenkins JOIN插件? 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 1)创建一个带有参数的小型作业,该参数应该使用一个小型套件进行测试运行

2) Edit this job to run on a list of slaves (where you have the proper environment) 2)编辑此作业以在从属设备列表上运行(您在适当的环境中)

3) Edit this build to allow concurrent builds 3)编辑此版本以允许并发版本

And now the hard part. 现在是困难的部分。

4) Create a small java program for computing the list of parameters for each job to run. 4)创建一个小型Java程序,以计算要运行的每个作业的参数列表。

5) Iterate trough the list and launch a new Jenkins job on a new thread. 5)遍历列表,并在新线程上启动新的Jenkins作业。

Put a Thread.sleep(5000) between runs in order to avoid communication errors 在运行之间放置Thread.sleep(5000)以避免通信错误

6) Join the threads 6)加入线程

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 要使用参数启动jenkins作业,请使用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 您可以通过以下代码使用https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin

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 构建流程插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM