简体   繁体   English

groovy.lang.MissingPropertyException - 读取输入 - Jenkinsfile

[英]groovy.lang.MissingPropertyException - Reading input - Jenkinsfile

Below is the Jenkinsfile(scripted pipeline) code snippet to select a Git repo in stage view:下面是在阶段视图中选择 Git 存储库的 Jenkinsfile(脚本化管道)代码片段:

            userInput = input(id: 'userInput',    
                                message: 'Do you want to build?',    
                                parameters: [
                                                [$class: 'ChoiceParameterDefinition', choices: "repo_1\nNone", name: 'Env']
                                            ]  
                            )


            if (userInput.Env == "repo_1") {
                print 'selected repo_1'
            }

requests the user to select a repository and click Proceed请求用户选择一个存储库并单击Proceed

On clicking Proceed button, jenkins throws error:单击Proceed按钮时,詹金斯抛出错误:

groovy.lang.MissingPropertyException: No such property: Env for class: java.lang.String

Manual build is only allowed for repo_1repo_1允许手动构建

Rest of the repositories suppose to be auto-triggered其余的存储库假设是自动触发的

Edit:编辑:

After making below changes,进行以下更改后,

node('worker_node'){

    def userIdCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
    def manualBuild =  userIdCause.size()

    stage("Auth-build") {

            timeout(2) {
                if (manualBuild) {

                    userInput = input(id: 'userInput',    
                                    message: 'Please select the repository',    
                                    parameters: [
                                                    [$class: 'ChoiceParameterDefinition', choices: "repo_1\nNone", name: 'Env']
                                                ]  
                                )

                    if (userInput == "None") {

                        error('Error output')
                    }
                    repositoryName = 'repo_1'
                }else if( !manualBuild && (repositoryName == 'repo_1')){

                    error('error output')
                }
            }
        }
}

I do not get UI after clicking BuildNow , I had to follow below process:单击BuildNow后我没有获得 UI,我必须遵循以下过程:

在此处输入图片说明


1) Why userInput.Env gives missing property exception error? 1) 为什么userInput.Env给出缺少属性异常错误?

2) input() api takes a minute to render input wizard. 2) input() api 需要一分钟来呈现输入向导。 Can we optimise?我们可以优化吗?

  1. No such property: Env for class: String - i believe that input function already returns the value of the single input. No such property: Env for class: String -我相信input函数已经返回了单个输入的值。
  2. The input definition is quite simple in your case and does not contain any code (just constants) - nothing to optimize in it. input定义在您的情况下非常简单,并且不包含任何代码(仅是常量)-无需进行任何优化。 Look for a time consumers in other places. 在其他地方寻找时间消费者。

Provide the "Choice Type" and "Referenced parameters" within Jenkins job to see the expected output.在 Jenkins 作业中提供“选择类型”和“参考参数”以查看预期输出。 In your case Referenced parameters is "Env"在您的情况下,引用的参数是“Env”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 groovy.lang.MissingPropertyException:在groovy中 - groovy.lang.MissingPropertyException: in groovy groovy.lang.MissingPropertyException:没有此类属性: - groovy.lang.MissingPropertyException: No such property: 从jenkinsfile groovy.lang.MissingPropertyException执行groovy脚本时发生异常:无此类属性:groovy.lang.Binding类的args - exception while executing groovy script from jenkinsfile groovy.lang.MissingPropertyException: No such property: args for class: groovy.lang.Binding groovy.lang.MissingPropertyException:没有这样的属性:类的getTestCaseByName: - groovy.lang.MissingPropertyException: No such property: getTestCaseByName for class: "Jenkins groovy.lang.MissingPropertyException:没有这样的属性 Bash" - Jenkins groovy.lang.MissingPropertyException: No such property Bash Jenkins管道groovy.lang.MissingPropertyException - Jenkins pipeline groovy.lang.MissingPropertyException Java中的嵌入式groovy,groovy.lang.MissingPropertyException:无此类属性: - Embedded groovy in Java, groovy.lang.MissingPropertyException: No such property: 错误:groovy.lang.MissingPropertyException没有这样的属性:sql对于类:Script9 - error: groovy.lang.MissingPropertyException No such property: sql for class: Script9 groovy.lang.MissingPropertyException:没有这样的属性:类的工具包:custom.SampleKeyword - groovy.lang.MissingPropertyException: No such property: Toolkit for class: custom.SampleKeyword groovy.lang.MissingPropertyException:没有这样的属性:任何类:WorkflowScript - groovy.lang.MissingPropertyException: No such property: any for class: WorkflowScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM