How to call a build flow from a build flow passing different parameters?

风格不统一 提交于 2019-12-08 06:15:24

问题


I have 3 Jobs (let's name it as job1,job2,job3) which all accepts same parameters. I have a build flow calling these jobs Eg Build Flow::

build(job1, param1 : "value1", param2 : "value2" )
build(job2, param1 : "value1", param2 : "value2" )
build(job3, param1 : "value1", param2 : "value2" )

As you see in the example all the jobs accept same parameters.

And I want to run the same sequence in the build flow (job1, job2, job3) with different parameter values. So Now I am having different build flows to pass different values to the parameter:

eg:

Build flow1---
build(job1, param1 : "value1", param2 : "value2" )
build(job2, param1 : "value1", param2 : "value2" )
build(job3, param1 : "value1", param2 : "value2" )

Build flow2---
build(job1, param1 : "value3", param2 : "value4" )
build(job2, param1 : "value3", param2 : "value4" )
build(job3, param1 : "value3", param2 : "value4" )

I am thinking to have a build flow as shared and able to pass parameters to it like : Example:::

Build flow
build(job1, param1 : $paramvalue1, param2 : $paramvalue2 )
build(job2, param1 : $paramvalue1, param2 : $paramvalue2 )
build(job3, param1 : $paramvalue1, param2 : $paramvalue2 )

And I want to call this build flow with different parameter values from another build flow.

Can I do that ??? If yes ,, 1. How to define and pass parameter to the flow ?


回答1:


You can use Workflow Plugin to achieve what you want.

  1. job1, job2 and job3 must be parameterized jobs with param1 and param2 as parameters (they can be freestyle jobs or whatever you want).
  2. Create a parameterized Workflow job with param1 and param2 as parameters. The workflow script would be something like this:

    build job: 'job1', parameters: 
      [[$class: 'StringParameterValue', name: 'param1', value: param1],
       [$class: 'StringParameterValue', name: 'param2', value: param2]]
    build job: 'job2', parameters: 
      [[$class: 'StringParameterValue', name: 'param1', value: param1],
       [$class: 'StringParameterValue', name: 'param2', value: param2]]
    build job: 'job3', parameters: 
      [[$class: 'StringParameterValue', name: 'param1', value: param1],
       [$class: 'StringParameterValue', name: 'param2', value: param2]]
    
  3. Then just run the top level job, it will ask you for parameters values and downstream jobs will be triggered (and top level parameters passed).



来源:https://stackoverflow.com/questions/32864248/how-to-call-a-build-flow-from-a-build-flow-passing-different-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!