jenkins - 运行我的 jenkinsfile 时找不到这样的字段 : field java. lang.String sinput 错误

标签 jenkins groovy jenkins-pipeline jenkins-declarative-pipeline

获取 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/

相关文章:

jenkins - 如何在Jenkins的动态管道中使用failFast

jenkins - 为什么 Jenkins 2.124 上找不到 s3Upload 构建步骤

groovy - 如何从 groovy 列表中删除重复值

groovy - 有没有办法让 @Builder 注释适用于不可变类?

Java,groovy REST 客户端比 Postman 慢 30 多倍

Jenkins :有关多项工作的每日电子邮件报告

jenkins - Jenkins 管道中的recipientProviders始终为空

jenkins - 如果触发构建失败,如何中止 Jenkins 作业

git - 有没有办法让 git 超过 http 超时?

svn - 与 Subversion 和 CVS 的持续集成