没有找到这样的字段:字段java.lang.String sinput错误,运行我的jenkinsfile


运行

我的 Jenkinsfile 时出现No such field found: field java.lang.String sinput错误。

我开发了一个 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 ? : '' 时不存在的变量。

引用来源3:

如果只列出一个参数,其值将变为输入步骤。如果列出了多个参数,则返回值将为映射以参数名称为键。如果未请求参数,则如果批准,步骤 将不返回任何内容。

您有 1 个参数,因此它成为输入步骤的值。不会创建地图。

云蜂 1 |云蜂 2 |管道输入步骤

很好...我有这样的问题,就我而言,这是我使用变量的方式当我喜欢$VARIABLE时,它不起作用,并且我遇到了此处描述的错误。但是,当我${VARIABLE}时 ->这一切都奏效了!!

对我来说

,问题是试图将length作为属性而不是length()作为方法进行访问。基本上缺少括号。

最新更新