2
votes

Assume I have a job at jenkins . and am trying to build it with parameters. Assume I have 2 parameters say para1 and para2.

para1 is of choice type parameter with 'yes' and 'No' value

I want para2 to be available in the UI only when 'yes' is selected in para1. otherwise i dont want this parameter itself displayed in the UI

We have following plugins

  1. https://wiki.jenkins.io/display/JENKINS/Active+Choices+Plugin
  2. https://wiki.jenkins.io/display/JENKINS/Reactive+Reference+Dynamic+Parameter+Controls

but these will allow to dynamically return values for a parameter based on any reference i.e any prev paramter value,

but not to disable a parameter itself from a job while it builds, like the user should not see the parameter name itself in UI while building the job , in my case para2 should not be seen when 'No' selected in para1 ...

any suggestion or workaround to acheive my scenario ?

Many Thanks

1

1 Answers

2
votes

What you are trying to achieve is not possible. A Jenkins job is defined by XML, displaying a new parameter based on a value of another one means that the XML definition of the job should be changed and the job reloaded again. What you can do is to have both parameters displayed in the job and then just use a simple if statement in your Jenkins pipeline to ignore para2 in case para1 value is no.

if (para1 == 'yes'){
    print "Do something that takes into account ${para2}"
} else {
    print "${para2} value is ignored"
}