0
votes

I have a multi job project which accepts some parameters and one of them is a choice parameter, because I'm new to Jenkins it is defined manually through UI and without using groovy.

When the parameters selected or passed, there is a single build that will run for the defined parameters.

I would like to apply some changes and achieve the following behavior:

Execute this same multi job project with all parameters per selected options in the choice parameter.

e.g If selected 2 options in the choice parameter - It will trigger the build twice sequentially or in parallel, some sort of a loop with the parameters it received.

I tried to get some information regarding this online but because I'm not familiar with the proper terminology to search for, all I get is groovy scripts or answers which not related to what I need.

How I can achieve this?

Thanks in advance.

1

1 Answers

0
votes

After additional search I came with the following solution:

  1. change the Choice parameter to Extended choice parameter to allow multiple selection.

  2. Create another job that will do the following:

    a. Parse the received parameters from the Extended Choice parameter using shell script with the delimiter that is set in the 'Extended choice parameter options'

    b. Execute build on the desired job from a loop by using API and passing the relevant parameters.

     echo $OPTIONS
    
     IFS=',' read -ra options_array <<< "$OPTIONS"
    
     for option in "${options_array[@]}"
     do
       echo $option
       curl -X POST "https://<user>:<password>@<jenkins_host>/job/<job_name>/buildWithParameters?parameter=${option}"
       sleep 5
     done
    
  3. In case there are no free executors - increase the number of executors to allow multiple job executions

  4. Edit job configuration that needs to be executed multiple times and enable the 'Execute concurrent builds if necessary' option.