Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To choose specific parameters while selecting inputs in Jenkins (Groovy) Pipeline, you can define the parameters in the Jenkinsfile and use the input step to prompt the user to select the desired parameters.

Here's an example:

pipeline {
   agent any
   parameters {
      string(name: 'PARAM1', defaultValue: '', description: 'Enter parameter 1')
      booleanParam(name: 'PARAM2', defaultValue: false, description: 'Select parameter 2')
   }
   stages {
      stage('User Input') {
         steps {
            input(
               id: 'userInput', message: 'Select parameters',
               parameters: [
                  [$class: 'BooleanParameterDefinition', defaultValue: params.PARAM2, description: 'Select parameter 2', name: 'PARAM2'],
                  [$class: 'StringParameterDefinition', defaultValue: params.PARAM1, description: 'Enter parameter 1', name: 'PARAM1']
               ]
            )
         }
      }
      stage('Build') {
         steps {
            // Build steps go here
         }
      }
   }
}

In this example, the pipeline defines two parameters - PARAM1 as a string and PARAM2 as a boolean. The input step is then used to prompt the user to select the values for these parameters. The parameters are defined as an array of parameter definitions, with each definition specifying the name, default value, and description of the parameter.

The input step returns the selected parameter values as an object that can be accessed using the same parameter names defined in the pipeline parameters block. These values can be used in subsequent stages of the pipeline.