I have a pipeline script that should work with and without parameters. So I have to check if the parameter is available.
I tried if(getBinding().hasVariable(\"mypa
See Getting Started with Pipeline, Build Parameters:
Build Parameters
If you configured your pipeline to accept parameters using the Build with Parameters option, those parameters are accessible as Groovy variables of the same name.
UPDATE
☑This build is parameterized → Add parameter → String Parameter:
STRING_PARAMETER
STRING_PARAMETER_VALUE
Pipeline → Definition: Pipeline script
→ Script:
def stringParameterExists = true
def otherParameterExists = true
try {
println " STRING_PARAMETER=$STRING_PARAMETER"
}
catch (MissingPropertyException e) {
stringParameterExists = false
}
try {
println " NOT_EXISTING_PARAMETER=$NOT_EXISTING_PARAMETER"
}
catch (MissingPropertyException e) {
otherParameterExists = false
}
println " stringParameterExists=$stringParameterExists"
println " otherParameterExists=$otherParameterExists"
Console Output:
[Pipeline] echo
STRING_PARAMETER=STRING_PARAMETER_VALUE
[Pipeline] echo
stringParameterExists=true
[Pipeline] echo
otherParameterExists=false
[Pipeline] End of Pipeline
Finished: SUCCESS