Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add String parameter to Jenkins with optional checkbox

I'm trying to add a String parameter to my jenkins build, but i can't find an option to make it optional, on the Jenkins WIKI i found a screeshot and there was an option to make it optional: https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build .

like image 568
Alex Brodov Avatar asked Aug 13 '14 10:08

Alex Brodov


2 Answers

All parameters are "optional". Unless it's a Validating String Parameter, Jenkins doesn't care what value you've entered or if you've entered anything at all.

The only thing that cares about the parameters is your job implementation, i.e. your scripts (bash) and other action that are configured to use the parameter.

If your parameter is called "Param", you can access it's value through:

  • ${Param} on Linux.
  • %Param% on Windows.

Edit to answer comments:
To pass params from a "parent" build to the downstream builds, depends on how you trigger the downstream builds. If you are using Call/Trigger Parameterized Build plugin (which you should be), then there is a simple option to pass parent parameters to downsteam builds. They will be available in child builds through the same param name, like ${Param} in the above example.

If you are triggering it some other way, there are a number of workarounds, mainly through storing them in a property file and then loading that property file in child build through EnvInject plugin

like image 78
Slav Avatar answered Oct 10 '22 03:10

Slav


Just provide a default value to the string parameter. As long as you do not change it, it's optional. You will simply have to check whether the parameter is set to the default and depending on the same, you can decide the course of action.

Check the option 'This build is parameterized'. Now select 'String Parameter'. To access the parameter from bash script, you just have to check the value of the variable that you assign to 'Name' textbox as shown in the fig.

enter image description here

echo "Country selected is $Country"
like image 41
Technext Avatar answered Oct 10 '22 04:10

Technext