Getting No such field found: field java.lang.String sinput error while running 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 {
// Variables for input
//def inputConfig apiinput
//def inputTest apilog
def apiinput
// Get the input
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?:''
// Echo to console
//echo("IQA Sheet Path: ${inputConfig}")
sh 'ssh king@1.2.3.4 "docker service logs ${apiinput} --raw"'
}
}
}
}
}
Solution:
I think 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 to it becomes the value of the input step. No map is created.
apiinput = userInput?:'' should eliminate the exception.