没有找到这样的字段:运行Jenkinsfile时,字段java.lang.String sinput错误
我开发了一个Jenkinsfile,它将接受用户输入,并进一步将用户输入作为变量在远程计算机上运行命令
阶段{
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"'
}
}
}
}
}
答案 0 :(得分:0)
我认为您错误地访问了变量sinput
。您的id: 'userInput'
确实直接代表用户输入的变量。您尝试访问调用apiinput = userInput.sinput?:''
时不存在的变量。
引用Source3:
如果仅列出一个参数,则其值将变为 输入步骤。 如果列出了多个参数,则返回值将是一个映射 由参数名称键入。如果不要求参数,则 如果批准,则步骤不返回任何内容。
您有1个参数,它成为输入步骤的值。没有创建地图。
apiinput = userInput?:''
应该消除该异常。
答案 1 :(得分:0)
嗯……我遇到了这样的问题,就我而言,这就是我使用变量的方式
当我喜欢 $VARIABLE
时,它不起作用,我遇到了类似于此处描述的错误。
然而,当我做了 ${VARIABLE}
-> 一切都奏效了!!!