首页 文章

使用Nexus Jenkins插件上传发布工件及其pom

提问于
浏览
1

我正在尝试使用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上传工件?

1 回答

  • 0

    实际上,您不需要配置上传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

相关问题