Search code examples
jenkinsjenkins-pluginsjenkins-pipelinejenkins-cli

How to define a Jenkins String parameter based on the Choice parameter selected


I am trying to setup a job , which requires the user to enter a input String on the Choice selected

I have seen various plugin, but all of them have the option of Choice parameters to be picked up from but not a string one

Scenario - Product ( abc, def , ghi , jkl) If the product name is only "def" then the user need to enter the dependent revision number as a string parameter "12356" , if any other product is selected then user shouldnt have any option to enter the string parameter

Any help is appreciated


Solution

  • This is not possible in Jenkins build with parameters page. Parameters are loaded all at once, and cannot have logic that depends on the value of another one.

    You have a few options, some easy ones are:

    1. In JenkinsFile/Pipeline, once job has kicked off, evaluate value of the product param and if 'def' Prompt user for subsequent input https://jenkins.io/doc/pipeline/steps/pipeline-input-step/
    2. Have the string field present as a param, but in the description note that it is only required when product == 'def' and otherwise ignore it regardless of value