首页 > 解决方案 > 如何在 jenkinsfile 中声明变量

问题描述

我正在尝试从 jenkinsfile 中的变量中获取 repo 详细信息。有人可以指导为什么这不起作用吗?

                        parameters {
                        string(defaultValue: "develop", description: 'enter the branch name to use', name: 'branch')
                        string(defaultValue: "repo1", description: 'enter the repo name to use', name: 'reponame')
                    }

             stage('Branch Update'){
                       dir("${param.reponame}"){
                            bat """ echo branch is ${params.branch}"""
                       }
                   }

当我运行上述内容时,我收到以下错误消息:

groovy.lang.MissingPropertyException:没有这样的属性:类的参数:groovy.lang.Binding [Pipeline] }

标签: jenkins-pipeline

解决方案


你有一个错字。而不是param.reponame应该是params.reponame.


推荐阅读