How to detect in Jenkins Workflow if parameterized build parameter exists or not? -
what best way can detect if parameter in parameterized build exists or not? closest solution found in groovy:
node { groovy.lang.binding mybinding = getbinding() boolean mybool = mybinding.hasvariable("string_param1") echo mybool.tostring() if (mybool) { echo string_param1 echo getproperty("string_param1") } else { echo "string_param1 not defined" } mybool = mybinding.hasvariable("did_not_define_this") if (mybool) { echo did_not_define_this echo getproperty("did_not_define_this") } else { echo "did_not_define_this not defined" } } is using getbinding() proper api this, or there better way?
you can use try-catch check existence of parameter:
try { echo test1 echo 'test1 defined' } catch (err) { echo 'test1 not defined' }
Comments
Post a Comment