Read interactive input in Jenkins pipeline to a variable

前端 未结 3 1542
我在风中等你
我在风中等你 2021-02-05 22:02

In a Jenkins pipeline, i want to provide an option to the user to give an interactive input at run time. I want to understand how can we read the user input in the groovy script

3条回答
  •  迷失自我
    2021-02-05 22:50

    Solution: In order to set ,get and access user input as a variable on jenkins pipeline, you should use ChoiceParameterDefinition , attaching a quick working snippet:

        script {
                // Define Variable
                 def USER_INPUT = input(
                        message: 'User input required - Some Yes or No question?',
                        parameters: [
                                [$class: 'ChoiceParameterDefinition',
                                 choices: ['no','yes'].join('\n'),
                                 name: 'input',
                                 description: 'Menu - select box option']
                        ])
    
                echo "The answer is: ${USER_INPUT}"
    
                if( "${USER_INPUT}" == "yes"){
                    //do something
                } else {
                    //do something else
                }
            }
    

提交回复
热议问题