问题
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 .
回答1:
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
回答2:
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.
echo "Country selected is $Country"
来源:https://stackoverflow.com/questions/25284030/how-to-add-string-parameter-to-jenkins-with-optional-checkbox