Active Choices Parameter In Jenkins

Active Choices Parameter

In this post, We will see how to use the Active Choices Parameter in Jenkins.

The Active choice parameter is used to parameterize your Jenkins job using scripting to make the dynamic and interactive job parameters. The Active choice parameter can be dynamically updated according to the written script. And it has many options with a parameter like check-boxes, radio-button, combo-boxes, or rich HTML UI widgets.

Once you install the Active Choice Plugin, It has been installed three types of parameters.
  1. Active Choices Parameter
  2. Active Choices Reactive Parameter
  3. Active Choices Reactive Reference Parameter.
Active choice parameters are scripted using Groovy, And the scripted variable could be used as a system environment variable.

By using the Active Choice Parameter We can perform or Achieve below mention operations.
  • Dynamically update your option.
  • Multi-Option Selection facility.
  • Render with UI Controls.
  • Filter option with available parameters.
Note:- Before the start Uses of Active Choice Parameter, I am supposing to you are already familiar with Jenkins freestyle job creation and Basic Parameter Uses in Jenkins Job.

If you are not familiar with Jenkins Job creation then Please checkout
Steps to Install and Uses Of Active Choices Parameter

Step:- 1. Open Jenkins and Click on this project is parameterized.
           >>> Check Active choice parameter option is available or not, If yes then select that option else 
                    follow the below steps to download the plugins and use them in your job.

Note:- For a new installation, the Steps are below:-

  1.   Click on Manage Jenkins
  2. Then open Plugin Manager 
  3. Click on the Available Tab, then search "Active Choices
  4. Then click on the checkbox, then click on the install button, and then Restart the Jenkins after installing the plugins.     

      
How you will be Use Active Choice Parameter:- 
  1. Select Active Choices Parameter option from parameters dropdown.
  2.  Type any Name, that you want to display on Job.
  3. Click on the groovy script.
  4. Then write the script according to the parameter value you want to pass. For example:- 
           return [ "Prod","Staging","Saturn","Other"]  it means the passed value will display according to choice type which I have selected, Here "Single Select", So it will display all value in dropdown like the choice parameter.

  5. Then put "return ['Script Error']" this value in the fallback script, it means any failure comes then what message will display on the console,
  6. Then Select choice type, Multiple options are available like- Single Select, Multiple Select, Radio Buttons, Check Boxes. Choose as per the requirements.
  7. You can also enable the filter options, which will help you to search the value from the dropdown, In case you will have multiple values.

  8. After putting all values, you can use this parameter name as a variable inside your job anywhere, Simply writing the $variableName, In My case, it will be $Project.

How to Use Active Choices Reactive Parameter

 As per the name, we can understand the Active choices Reactive parameter is an extended form of Active Choices Parameter, which Means we can use this parameter to update the value at runtime while building the job by using the reference value of the Active choices parameter.

Please look at this image, I have put the condition in the groovy scripting section and passed the References parameter "Project" which is the Active choice parameter variable name.


I have used the groovy code, which are 
if(Project.equals("Prod")){
 return [ "@LoginTest:selected"] 
}else if (Project.equals("Staging")){
return [ "@LoginTest:selected"]
}else if(Project.equals("Saturn")){
 return [ "@LoginTest:selected"]
}else if (Project.equals("Other")){
return [ "@LoginTest","@LogOut" ]
}

In the description, you can use an HTML line to look interactive, I have used

<h3>Product Tag Discription</h3> 
<ul>  
<li><p>@LoginTest  - For LogIn functionality verification</br></li> 
</ul> 
<p>By Default ProductTag includes According to Project Selection</p> 
<p><b>Note :</b> If Project is <b>Other</b> then ProductTag is mandatory</p>

Then In the choice type, you can select value according to your requirements. I have used ( check box ) to select multiple values at a time)

>>> Important Note:- Always pass the value 1 in FIlter start at filed to avoid the ( Space ) between values when you select multiple values from options. 

Then we can use this parameter anywhere in our job, Similar to other parameters. like ( $ProductTag)


Post a Comment

Previous Post Next Post