【问题标题】:Upload a release artifact and its pom with Nexus Jenkins Plugin使用 Nexus Jenkins 插件上传发布工件及其 pom
【发布时间】:2018-11-29 18:13:25
【问题描述】:

我正在尝试使用 Nexus Jenkins 插件上传带有 pom 文件的发布工件。

Nexus 存储库配置了“禁用重新部署”的部署策略,因此无法覆盖发布。

为了简化问题,假设我只想上传我的自定义 pom:

pipeline {
    agent any
    stages {
        stage('Publish') {
            steps {
                nexusPublisher nexusInstanceId: 'nexusJose', nexusRepositoryId: 'nexusJose',
                    packages: [ 
                        [$class: 'MavenPackage', 
                        mavenAssetList: [ 
                            [classifier: '', 
                            extension: 'pom', 
                            filePath: "/libs/mylib-4.6.0.pom"],
                        ],
                        mavenCoordinate: [
                            artifactId: "mylib", 
                            groupId: "com.codependent.libs", 
                            packaging: "pom", version: "4.6.0"]
                        ]
                    ]
            }
        }
    }
}

由于某些原因,当 nexusPublisher 执行时,Nexus 在执行 pom 上传之前为这些坐标创建一个默认 pom,因此实际 pom 的上传失败,因为它已经存在于存储库中:

Uploading Maven asset with groupId: mylib artifactId: com.codependent.libs version: 4.6.0 To repository: thirdparty
Upload of /libs/mylib-4.6.0.pom failed
Failing build due to failure to upload file to Nexus Repository Manager Publisher
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
com.sonatype.nexus.api.exception.RepositoryManagerException: Unable to upload component: Bad Request <html><body><error>Repository with ID='thirdparty' does not allow updating artifacts.</error></body></html>

如何使用自己的 pom 上传工件?

【问题讨论】:

    标签: jenkins jenkins-plugins jenkins-pipeline nexus


    【解决方案1】:

    实际上,您不需要配置上传 pom.xml 文件 - Nexus Jenkins 插件会自动上传您的 pom.xml 文件。您只需要配置发布工件的上传。

    因此,在您的情况下,您可以使用以下配置,并且您的“mylib-4.6.0.pom”应该会自动上传:

    pipeline {
        agent any
        stages {
            stage('Publish') {
                steps {
                    nexusPublisher nexusInstanceId: 'nexusJose', nexusRepositoryId: 'nexusJose',
                        packages: [ 
                            [$class: 'MavenPackage', 
                            mavenAssetList: [ 
                                [classifier: '', 
                                extension: '', 
                                filePath: "${path-to-artifact}/mylib-4.6.0.jar"],
                            ],
                            mavenCoordinate: [
                                artifactId: "mylib", 
                                groupId: "com.codependent.libs", 
                                packaging: "jar", version: "4.6.0"]
                            ]
                        ]
                }
            }
        }
    }
    

    这个页面很有用: https://support.sonatype.com/hc/en-us/articles/227256688-How-do-I-configure-the-Nexus-Jenkins-Plugin

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-04
      • 2017-12-07
      • 2012-02-17
      • 2016-12-07
      • 1970-01-01
      • 2014-04-05
      • 2019-07-06
      相关资源
      最近更新 更多