Read interactive input in Jenkins pipeline to a variable

前端 未结 3 1502
我在风中等你
我在风中等你 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:47

    For saving to variables and a file, try something like this based on what you had:

    pipeline {
    
        agent any
    
        stages {
    
            stage("Interactive_Input") {
                steps {
                    script {
    
                        // Variables for input
                        def inputConfig
                        def inputTest
    
                        // Get the input
                        def userInput = input(
                                id: 'userInput', message: 'Enter path of test reports:?',
                                parameters: [
    
                                        string(defaultValue: 'None',
                                                description: 'Path of config file',
                                                name: 'Config'),
                                        string(defaultValue: 'None',
                                                description: 'Test Info file',
                                                name: 'Test'),
                                ])
    
                        // Save to variables. Default to empty string if not found.
                        inputConfig = userInput.Config?:''
                        inputTest = userInput.Test?:''
    
                        // Echo to console
                        echo("IQA Sheet Path: ${inputConfig}")
                        echo("Test Info file path: ${inputTest}")
    
                        // Write to file
                        writeFile file: "inputData.txt", text: "Config=${inputConfig}\r\nTest=${inputTest}"
    
                        // Archive the file (or whatever you want to do with it)
                        archiveArtifacts 'inputData.txt'
                    }
                }
            }
        }
    }
    

提交回复
热议问题