简体   繁体   中英

groovy.lang.MissingPropertyException - Reading input - Jenkinsfile

Below is the Jenkinsfile(scripted pipeline) code snippet to select a Git repo in stage view:

            userInput = input(id: 'userInput',    
                                message: 'Do you want to build?',    
                                parameters: [
                                                [$class: 'ChoiceParameterDefinition', choices: "repo_1\nNone", name: 'Env']
                                            ]  
                            )


            if (userInput.Env == "repo_1") {
                print 'selected repo_1'
            }

requests the user to select a repository and click Proceed

On clicking Proceed button, jenkins throws error:

groovy.lang.MissingPropertyException: No such property: Env for class: java.lang.String

Manual build is only allowed for repo_1

Rest of the repositories suppose to be auto-triggered

Edit:

After making below changes,

node('worker_node'){

    def userIdCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
    def manualBuild =  userIdCause.size()

    stage("Auth-build") {

            timeout(2) {
                if (manualBuild) {

                    userInput = input(id: 'userInput',    
                                    message: 'Please select the repository',    
                                    parameters: [
                                                    [$class: 'ChoiceParameterDefinition', choices: "repo_1\nNone", name: 'Env']
                                                ]  
                                )

                    if (userInput == "None") {

                        error('Error output')
                    }
                    repositoryName = 'repo_1'
                }else if( !manualBuild && (repositoryName == 'repo_1')){

                    error('error output')
                }
            }
        }
}

I do not get UI after clicking BuildNow , I had to follow below process:

在此处输入图片说明


1) Why userInput.Env gives missing property exception error?

2) input() api takes a minute to render input wizard. Can we optimise?

  1. No such property: Env for class: String - i believe that input function already returns the value of the single input.
  2. The input definition is quite simple in your case and does not contain any code (just constants) - nothing to optimize in it. Look for a time consumers in other places.

Provide the "Choice Type" and "Referenced parameters" within Jenkins job to see the expected output. In your case Referenced parameters is "Env"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM