Installation Active Choice parameter - Groovy Script |
Prerequisite:
Jenkins installed Up and running on your target master machine.Jenkins URL accessible
On the Jenkins Dashboard, select the Manage Jenkins, Plugin- Manager, In the Available tab search for word 'Active', where you can see Active Choice plugin and choose installation option, and this will enables three different parameters in the "Add Paramters" list. They are :
1. Active choice parameter
2. Active Choice Reactive parameter
3. Active choice Reactive Reference parameter
Here In my example I will use two of them, Firstly Active Choice Parameter for "environment".
Create new item Name: active_project select a freestyle project click OK button.
In the General tab, select the checkbox for 'This project is parameterized'.
Step 1: Install Active Choice plugin
On the Jenkins Dashboard, select the Manage Jenkins, Plugin- Manager, In the Available tab search for word 'Active', where you can see Active Choice plugin and choose installation option, and this will enables three different parameters in the "Add Paramters" list. They are :
1. Active choice parameter
2. Active Choice Reactive parameter
3. Active choice Reactive Reference parameter
Here In my example I will use two of them, Firstly Active Choice Parameter for "environment".
Create new item Name: active_project select a freestyle project click OK button.
In the General tab, select the checkbox for 'This project is parameterized'.
Step 2: Add Parameter - Active Choice Parameter
Please enter the following as per your project needs. Offcourse here we are starting Groovy code snippets which doesn't required any expert level coding.
Name: environment
Let's define the "Active Choice Reactive Parameter" as sub_env, Here 'sub_env' parameter is depends on the 'environment' parameter which is defined in the previous step.
Name: sub_env
Script: Select Grovy script:
Add the following groovy code:
Groovy fall back code:
Select Active Choice Reactive Parameter Enter the following values
Name: datacenter
Final step
Script: Groovy Script
Add the following groovy code:
return[ 'Live', 'QA', 'Dev' ]Screen shot:
Adding Active Choice parameter adding Groovy list |
Step 3: Add Parameter - Active Choice Reactive Parameter
Let's define the "Active Choice Reactive Parameter" as sub_env, Here 'sub_env' parameter is depends on the 'environment' parameter which is defined in the previous step.
Name: sub_env
Script: Select Grovy script:
Add the following groovy code:
if (environment.equals("Live")){ return ["Prod","DR"] } else if (environment.equals("QA")){ return ["FT","UAT","Stage"] } else if (environment.equals("Dev")){ return ["Dev-Feature","Dev-Release"] } else{ return ["Please select environment"] }On the same parameter block "Single select" from the dropdown
Groovy fall back code:
return ["Select proper environment"]Now enter the environment as value for the 'Reference parameter'.
Adding Active choice reactive parameter |
Step 4: Add Parameter list - Active Choice Reactive Reference parameter
Select Active Choice Reactive Parameter Enter the following values
Name: datacenter
Script: Select Groovy script:
Add the following groovy code:
Reference parameter: sub_env
Finally save the configuration of the project.
Add the following groovy code:
if(sub_env.equals("Prod")){ return ["Prod environment at HYD region"] } else if(sub_env.equals("DR")){ return["DR environment at GG region"] } else if(sub_env.equals("FT")){ return ["FT environment at HYD region"] } else if(sub_env.equals("UAT")){ return["UAT environment at GG region"] } else if(sub_env.equals("Stage")){ return["Stage environment at GG region"] } else if(sub_env.equals("Dev-Feature")){ return["Dev-Feature environment at GG region"] } else if(sub_env.equals("Dev-Release")){ return["Dev-Release environment at GG region"] } else{ return ["dont miss sub-env"] }Groovy fall back code: return ["Select proper sub-env"]
Reference parameter: sub_env
Finally save the configuration of the project.
Final step
Verify saved script in Jenkins UI by clicking “Build with Parameters”.
Document References https://plugins.jenkins.io/uno-choice/
No comments:
Post a Comment