How to call a build flow from a build flow passing

2019-06-04 19:31发布

问题:

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).