Search code examples
jenkinsjenkins-pipelinejenkins-plugins

How to conditionally hide parameter?


I am trying to create a jenkins pipeline job with parameters. I want the parameters to show up conditionally. The condition depends on a selection of a previous parameter.

I have tried the Active choices plug-in. It allows me to choose a value of a parameter conditionally. I want the whole parameter to appear in the UI conditionally.

Is it possible with jenkins pipeline files?


Solution

  • I do not believe this is possible. In the case of declarative/scripted pipelines, parameters are 'post-processed' meaning essentially the ones you see are what was evaluated in the previous 'run/build'. Which is why it takes a build before 'Build with Parameters' becomes available.

    As an alternative, (if you're using scripted/declarative pipelines) you could use an Input step and make it trigger conditionally.

    if ( x == true ) {
        def userInput = input(
           id: 'userInput', message: 'Let\'s promote?', parameters: [
           [$class: 'TextParameterDefinition', defaultValue: 'uat', description: 'Environment', name: 'env'],
           [$class: 'TextParameterDefinition', defaultValue: 'uat1', description: 'Target', name: 'target']
        ])
    }
    

    Example pulled from: https://support.cloudbees.com/hc/en-us/articles/204986450-Pipeline-How-to-manage-user-inputs