【问题标题】:Use variable in nexusArtifactUploader/Jenkinsfile在 nexusArtifactUploader/Jenkinsfile 中使用变量
【发布时间】:2023-03-31 16:40:01
【问题描述】:

我有这个 Jenkins DSL 脚本,它从 pom.xml 文件中获取版本并在 nexusArtifactUploader 中使用该版本。这目前不起作用,我收到 "groovy.lang.MissingPropertyException: No such property: version for class: groovy.lang.Binding" 错误。我是 Groovy/Jenkins DSL 的新手,不知道如何让它工作。

stage('Nexus') {
        steps {
            script {
                def pom = readMavenPom file: 'pom.xml'
                echo pom.version

                nexusArtifactUploader(
                        nexusVersion: 'nexus3',
                        protocol: 'http',
                        nexusUrl: 'nexus.example.com:8080/nexus',
                        groupId: 'com.example',
                        **version: "${pom.version}",**
                        repository: 'example',
                        credentialsId: 'ciuser',
                        artifacts: [
                            [artifactId: 'com.example',
                            file: 'com.example-' + version + '.jar',
                            type: 'jar']
                        ]
                )
            }
        }
    }

【问题讨论】:

    标签: jenkins groovy jenkins-plugins jenkins-pipeline


    【解决方案1】:

    我认为你的错误实际上是在这一行:

    file: 'com.example-' + version + '.jar',
    

    尝试将version 替换为pom.version

    【讨论】:

    • 感谢您的留言。让我试试看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多