获取 No such field found: field java.lang.String sinput
运行我的 Jenkinsfile 时出错。
我开发了一个 Jenkinsfile,它可以接受用户输入,并进一步在远程机器上运行一个命令,将用户输入作为变量
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?:''
}
}
}
}
最佳答案
解决方案 :
apiinput = userInput?:''
将消除您的问题。
解释:
您正在访问您的变量 sinput
错。您的 id: 'userInput'
确实直接代表用户输入的变量。您在调用 apiinput = userInput.sinput?:''
时尝试访问不存在的变量.
引自 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.
您有 1 个参数,因此它成为输入步骤的值。没有创建 map 。
Cloudbees 1 | Cloudbees 2 | Pipeline Input Step
关于jenkins - 运行我的 jenkinsfile 时找不到这样的字段 : field java. lang.String sinput 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56507729/