Issue
I have something like this on my jenkins pipeline
properties([
parameters([
booleanParam(description: 'Merge master to this branch', name: 'merge_master', defaultValue: false),
someOtherParameters
])
])
Obviously the first parameter that doesn't make sense if the pipeline is running on master branch. So, how can I have this parameter only if the pipeline is not running on master branch?
Solution
If you haven't found a way yet, you could just add the elements to the parameters list conditionally like this
def list = []
if (env.BRANCH_NAME != 'master') {
list.add(booleanParam(description: 'Merge master to this branch', name: 'merge_master', defaultValue: false))
}
//example list.add(otherParams)
//finally
properties([parameters(list)])
More on adding to lists in groovy can be found here.
Answered By - hakamairi
Answer Checked By - Marie Seifert (JavaFixing Admin)