overexchange
overexchange

Reputation: 1

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:

enter image description here


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

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

Upvotes: 0

Views: 1549

Answers (2)

manisha sona
manisha sona

Reputation: 1

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

Upvotes: 0

daggett
daggett

Reputation: 28634

  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.

Upvotes: 1

Related Questions