【问题标题】:Jenkins: parallelize test executionJenkins:并行化测试执行
【发布时间】:2015-07-31 19:39:22
【问题描述】:

我开始在我的项目中使用 Jenkins,我正在尝试在 Jenkins 的 4 个文件中并行化我的测试套件(Rspec 测试用例)

spec/features/
|-- test1.rb
|-- test2.rb
|-- test3.rb
|-- test4.rb

我们可以使用以下命令运行所有测试用例,它将依次运行在 test1.rb ..test4.rb 中编写的所有测试,大约需要 1 小时。

script spec/features/

如果你想从每个测试文件中执行测试用例,我们可以像这样运行

script spec/features/test1.rb

现在我想并行化这些测试用例,可以将运行时间从 1 小时缩短到 15 分钟,所有这些测试用例都可以在一台机器上并行运行

我在 Jenkins 中遵循以下方法

1) 设置新作业“Main_Test_job”

2)

Selected "Trigger/Call builds on other projects"
projects to build " Child_test_job"
Build on same node
Predefined Parameters TEST_UNIT=test1.rb
Block until the triggered projects finish their builds ( Not selected this)

添加触发器--->

Selected "Trigger/Call builds on other projects"
projects to build " Child_test_job"
Build on same node
Predefined Parameters TEST_UNIT=test2.rb
Block until the triggered projects finish their builds ( Not selected this)

添加触发器--->

Selected "Trigger/Call builds on other projects"
projects to build " Child_test_job"
Build on same node
Predefined Parameters TEST_UNIT=test3.rb
Block until the triggered projects finish their builds ( Not selected this)

添加触发器--->

Selected "Trigger/Call builds on other projects"
projects to build " Child_test_job"
Build on same node
Predefined Parameters TEST_UNIT=test4.rb
Block until the triggered projects finish their builds ( Not selected this)

3)

   Created job "Child_test_job" as which was included in main_test_job like below
   Select Build step "Execute Shell" with below command
   script spec/$TEST_UNIT

当我启动“Main_Test_job”时,它会自动在同一台机器上启动 4 个 Child_Test_Jobs,这会将我的总运行时间减少到 15 分钟。

  • 但在这种情况下,“Main_test_job”无法监控 4 的状态 child_test_jobs,总是启动后立即成功 4
    子作业

  • “在触发的项目完成构建之前阻止”此选项 监控子作业,但如果我们为所有子作业选择此选项, 它们是按顺序运行而不是并行运行。

我不能使用加入插件,因为我没有运行不同的作业,而是多次触发同一个作业。

我的想法:

  1. 每个 test.rb 都有单独的作业,并使用连接触发器来监控 所有作业的状态

  2. 有一些 shell 脚本作为“Main_Test_job”的构建后任务 它将汇总/监控每个作业的状态/结果。

我认为这在许多组织中一定是一个常见的场景,并且 Jenkins 必须有一种简单的方法来实现这一点。 请让我知道您的方法/想法。可能我在这里遗漏了一些东西。

【问题讨论】:

    标签: jenkins continuous-integration jenkins-plugins


    【解决方案1】:

    如果您的作业可以在同一台机器上并行运行,那么您可能会对 Multijob 插件感兴趣。它并行启动作业,但等待所有作业完成。

    【讨论】:

    • 感谢 NotAgain..,这符合我的要求。我应该对所有可用的插件进行更多研究,但是它们有很多:)
    【解决方案2】:

    你也可以使用Build Flow Plugin

    您可以使用此插件运行任何类型的作业。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-05
      • 1970-01-01
      相关资源
      最近更新 更多