Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No such field found: field java.lang.String sinput error while running my jenkinsfile

Getting No such field found: field java.lang.String sinput error while running my Jenkinsfile.

I have developed a Jenkinsfile that would take a user input and further would run a command on remote machine taking the user input as a variable

stages {
    stage("Interactive_Input") {
        steps {
            script {
                def apiinput
                def userInput = input(
                        id: 'userInput', message: 'This is my project',
                        parameters: [
                                string(defaultValue: 'None',
                                        description: 'Enter the name of the service',
                                        name: 'sinput'),
                                
                        ])
                // Save to variables. Default to empty string if not found.
                apiinput = userInput.sinput?:''
            }
        }
    }
}
like image 877
Vicky Avatar asked Dec 22 '22 22:12

Vicky


2 Answers

Solution:

apiinput = userInput ? : ''

Explanation:

You are accessing your variable sinput wrongly. Your id: 'userInput' does stand directly for the variable of the user input. You try to access a variable that does not exist when you call apiinput = userInput.sinput ? : ''.

Quoting from Source3:

If just one parameter is listed, its value will become the value of the input step. If multiple parameters are listed, the return value will be a map keyed by the parameter names. If parameters are not requested, the step returns nothing if approved.

You have 1 parameters so it becomes the value of the input step. No map is created.

Cloudbees 1 | Cloudbees 2 | Pipeline Input Step

like image 150
Michael Kemmerzell Avatar answered Dec 26 '22 11:12

Michael Kemmerzell


well ... I had such an issue and in my case it was the way I was using variables When I did like $VARIABLE it wasn't working and I had an error like the one described here. However when I did ${VARIABLE} -> it has all worked!!!

like image 36
Гдето Якутский Avatar answered Dec 26 '22 11:12

Гдето Якутский