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?:''
}
}
}
}
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
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!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With