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.
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
Asked: 2021-07-30 11:00:00 +0000
Seen: 16 times
Last updated: Oct 19 '21
What is the process of serializing groovy traits using Gson?
What is the method to transform an XML hierarchical arrangement to CSV utilizing groovy?
How can Quartz be utilized in Grails?
How to modify the node label in Jenkins once the job has been completed successfully?
What are the typical approaches found in a Gradle build script?
How can a list of objects in Groovy be created from Json?
How to provide the workspace path as a file to setReportDir in XmlTestRunListener using groovy?