Ask Your Question
3

How to choose specific parameters while selecting inputs in Jenkins (Groovy) Pipeline?

asked 2021-07-30 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-10-19 15:00:00 +0000

david gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-07-30 11:00:00 +0000

Seen: 16 times

Last updated: Oct 19 '21