Use (Boolean, Choice, Credentials, File, Password, String) Parameters In Jenkins


In this post, We will see how to set parameters to your Jenkins job.

The parameter is helpful when we need to pass some value to our job So that our job would be run or trigger by using the passed value by parameter.

In Jenkins, there are many types of the parameter has been categorized, We will see one by one all parameter which is more in our daily use.

Types of Parameters:-
  1. Boolean Parameter
  2. Choice Parameter
  3. Credentials Parameter
  4. File Parameter
  5. Password Parameter
  6. String Parameter
 1. Boolean Parameter 
The boolean parameter is used to pass the value to your Jenkins job in a true or false.

Note:- Before configuring the boolean parameter in Jenkins, I am assuming you have already created a freestyle or sample job in Jenkins. If you have been not created your Jenkins Job then please visit my blog for Jenkins job creation: - Link Click Here

Steps to configure the boolean parameter in Jenkins.

Step:- 1. Open Jenkins Job and then Click on Configure Button
Step:- 2. After click on the configure button, click on the checkbox for This project is parameterized.


Then Add Parameter drop-down will be displayed there like above in the image. And then select the parameter from the drop-down option.

Step: - 3. Click on Boolean Parameter


Step: - 4 Enter parameter name in the Name input box or Put some meaning full description in the Description input box  

Note: -  Default value is tick enable if you want to boolean parameter would be selected by default.

Step:- 4. Use the parameter as a variable inside your job with ${parameter_name} or $parameter_name way

Inside execute shell build option I have used declared boolean parameter.
Then click on the Apply button and Save Button.

Step:- 5.  Click on Build with Parameter or Select created parameter or keep as it is.

Then click on the Build button.

Step:- 6. You can see in the console output parameter value is printed as false because I did not click on the checkbox.

2. Choice Parameter 
The choice parameter is used to select the value from the drop-down as we pass multiple options during parameter configuration.

Please follow the same step as above we have mentioned for the Boolean parameter. Only need to select a choice parameter option from the Add Parameters dropdown. 
 

Then enter expected details

  • Parameter name in the Name input box.
  • Put choices option in the  Choices box.
  • Put some meaning full description in the Description input box.
  • Then use the parameter variable with $BrowserType or $parameter_name inside your Job.
3. Credentials Parameter
The credentials parameter is used to pass selected credentials during a building job. The selected credential is available through variable substitution in some other parts of the configuration. The string value will be the ID of the credential. A supporting plugin can thus use the ID to retrieve the selected credential and expose it to the build in an appropriate way.
 
Please follow the same step as above we have mentioned for the Boolean parameter. Only need to select credentials parameter option from the Add Parameters dropdown. 

 
Then enter all mandatory field:-

  • Parameter name in the Name input box.
  • Put Credential type according to requirement or leave as it is Any
  • Select Default value from the saved credentials list. 
  • Put some meaning full description in the Description input box.
  • Then use the parameter variable with $gitlabCredential or $parameter_name inside your Job.
4. File Parameter
The file parameter is used to copy a file from your local directory location to mention file path location in the workspace, So that during the build execution passed file will be included.

Please follow the same step as above we have mentioned for the Boolean parameter. Only need to select the File parameter option from the Add Parameters dropdown. 


Then enter all mandatory fields.

  • Put the File location where your selected file will be copied.
  • Put some meaning full description in the Description input box.
5. Password Parameter
The password parameter is used to pass password detail during build a job. Password parameter and String parameter is almost the same, Only in password parameter the hidden with .........................

Please follow the same step as above we have mentioned for the Boolean parameter. Only need to select the Password parameter option from the Add Parameters dropdown. 

 
Then enter all mandatory fields.

  • Parameter name in the Name input box.
  • Put Default value, If we want otherwise leave blank.
  • Put some meaning full description in the Description input box.
  • Then use the parameter variable with $EnvPassword or $parameter_name inside your Job.
6. String Parameter
The String parameter is used to simple as a text parameter value, where users can enter a string value, which you can use during a build, either as an environment variable, or through variable substitution in some other parts of the configuration.

Please follow the same step as above we have mentioned for the Boolean parameter. Only need to select the String parameter option from the Add Parameters dropdown. 


Then enter all mandatory options.

  • Parameter name in the Name input box.
  • Put Default value, If we want otherwise leave blank.
  • Put some meaning full description in the Description input box.
  • Then use the parameter variable with $URL or $parameter_name inside your Job.
Then click on Apply and Save button.

After applying the mentioned parameter the Job UI would be displayed like below. 
Then put the parameter value or select value according to requirment and then Build a job.

Then get result output in the console log, Like we have seen in Boolean Parameter.

I hope you have enjoyed this post, Please mention your valuable comment in the comment box.
 

Post a Comment

Previous Post Next Post