詹金斯,如何运行另一项工作几次,但参数不同?

时间:2016-08-20 04:45:20

标签: jenkins

在测试执行之前,我有一个用于前置条件的作业。

它具有发布优惠和搜索的功能:

enter image description here

我必须启动它两次:

  • 发布优惠
  • 用于发布搜索

当然,2次跑步的参数不同。

如何自动完成这些发布,而不进行两次?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

  • 添加新项目
  • 选择Build Flow类型
  • 选择This build is parameterized

我添加了两次启动MyAnotherJobWhichIWantToRun所需的所有参数:

enter image description here

  • 现在我必须拿走这些参数,然后两次启动我想要的工作 不需要的参数设置为0

可以使用Groovy脚本实现。只需写下Define build flow using flow DSL

 ignore(ABORTED) {
    ignore(FAILURE) { 
       // offers
        b = build("MyAnotherJobWhichIWantToRun",                   
                 "config.test.timeout.min": params["offers.duration.min"],     

                 "throughput.freight.offer.permin": params["throughput.freight.offer.permin"],
                 "throughput.vehicle.offer.permin": params["throughput.vehicle.offer.permin"],

                 "throughput.freight.search.permin": "0",
                 "throughput.freight.reg.search.permin": "0",
                 "throughput.freight.cnt.search.permin": "0",
                 "throughput.vehicle.search.permin": "0",
                 "throughput.vehicle.reg.search.permin": "0",
                 "throughput.vehicle.cnt.search.permin": "0"
                )
    }
    ignore(FAILURE) {
       // searches
        b = build("MyAnotherJobWhichIWantToRun", 
                "throughput.freight.offer.permin": "0",
                 "throughput.vehicle.offer.permin": "0",

                 "config.test.timeout.min": params["searches.duration.min"],

                 "throughput.freight.search.permin": params["throughput.freight.search.permin"],
                 "throughput.freight.reg.search.permin": params["throughput.freight.reg.search.permin"],
                 "throughput.freight.cnt.search.permin": params["throughput.freight.cnt.search.permin"],
                 "throughput.vehicle.search.permin": params["throughput.vehicle.search.permin"],
                 "throughput.vehicle.reg.search.permin": params["throughput.vehicle.reg.search.permin"],
                 "throughput.vehicle.cnt.search.permin": params["throughput.vehicle.cnt.search.permin"]
                )
    }
}

下一个块:

  ignore(ABORTED){
    ignore(FAILURE) {

即使首先失败或中止,也会启动第二个作业。