首页 > 解决方案 > 未找到此类字段:运行我的 jenkinsfile 时出现字段 java.lang.String sinput 错误

问题描述

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?:''
            }
        }
    }
}

标签: jenkinsgroovyjenkins-pipelinejenkins-declarative-pipeline

解决方案


解决方案

apiinput = userInput?:''将消除您的问题。


解释:

sinput错误地访问了变量。您id: 'userInput'确实直接代表用户输入的变量。您尝试访问调用时不存在的变量apiinput = userInput.sinput?:''

引用 Source3:

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

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

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


推荐阅读