How to add String parameter in Jenkins with optional flag

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

+5
source share
2 answers

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

The only thing about parameters is the implementation of your work, that is, your scripts (bash) and other actions that are configured to use the parameter.

If your parameter is called Param , you can access it through:

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

Change response to comments:
To pass parameters from the "parent" assembly to downstream assemblies depends on how you run the downstream assemblies. If you use the Call / Trigger Parameterized Build plugin (which should be), then there is a simple option to pass the parent parameters to the downsteam builds. They will be available in child assemblies using the same parameter name, for example ${Param} in the example above.

If you run it in any other way, there are a number of workarounds, mainly by storing them in the properties file and then loading this property file in the child construct via the EnvInject plugin

+7
source

Just provide a default value for the string parameter. Until you change it, this is optional. You just need to check if the parameter is set by default and depending on whether you can decide the course of action.

Check the option "This assembly is parameterized." Now select "String Parameter". To access a parameter from a bash script, you just need to check the value of the variable that you assigned to the Name text box, as shown in the figure.

enter image description here

 echo "Country selected is $Country" 
+4
source

Source: https://habr.com/ru/post/1200210/


All Articles