[workflow] how to tell if build parameter is set?

11 views
Skip to first unread message

Craig Rodrigues

unread,
Dec 29, 2015, 6:40:36 PM12/29/15
to Jenkins Users
I want to have a single workflow groovy file, shared across multiple
Jenkins builds.
If I have a workflow, where "this build is parameterized" is set,
how can I detect in the workflow if a particular build parameter is defined or not,
without throwing an exception?

The closest solution I found was to do this 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 is 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 is not defined"
   }
}

Is that the best way to do it, or is there a better way?

--
Craig
Reply all
Reply to author
Forward
0 new messages