如何将多个工件部署到nexus?

时间:2016-11-20 13:33:09

标签: jenkins nexus

我在jenkins管道中使用Nexus Artifact Upload将工件上传到Nexus,在使用此代码部署的管道中,它非常适合部署一个工件。但是我如何部署多重工件:

Stage 'Nexus Deploy'
     nexusArtifactUploader
        artifactId: 'com.example.project',
        file: 'server/jetty-project/target/jetty-project-0.0.1-SNAPSHOT.war',
        groupId: 'test-javaproject',
        type:'war',
        nexusPassword: 'admin123',
        nexusUrl: 'XX.XX.XX.XX:8080/nexus',
        nexusUser: 'admin',
        nexusVersion: 'nexus3',
        protocol: 'http',
        repository: 'maven-snapshots',
        version: '0.0.1-SNAPSHOT'

在文档中说它可以部署多个像

这样的工件
freeStyleJob('NexusArtifactUploaderJob') {
    steps {
      nexusArtifactUploader {
        nexusVersion('nexus2')
        protocol('http')
        nexusUrl('localhost:8080/nexus')
        groupId('sp.sd')
        version('2.4')
        repository('NexusArtifactUploader')
        credentialsId('44620c50-1589-4617-a677-7563985e46e1')
        artifact {
            artifactId('nexus-artifact-uploader')
            type('jar')
            classifier('debug')
            file('nexus-artifact-uploader.jar')
        }
        artifact {
            artifactId('nexus-artifact-uploader')
            type('hpi')
            classifier('debug')
            file('nexus-artifact-uploader.hpi')
        }
      }
    }
}

但我想知道如何在jenkinsfile中制作它?

2 个答案:

答案 0 :(得分:3)

请在Jenkins文件中找到nexusArtifactUploader的以下语法。

nexusArtifactUploader artifacts: [
   [artifactId: 'nexus-artifact-uploader', classifier: 'debug', file: 'nexus-artifact-uploader.jar', type: 'jar'], 
   [artifactId: 'nexus-artifact-uploader', classifier: 'debug', file: 'nexus-artifact-uploader.hpi', type: 'hpi']
], 
credentialsId: '44620c50-1589-4617-a677-7563985e46e1', 
groupId: 'sp.sd', 
nexusUrl: 'localhost:8080/nexus', 
nexusVersion: 'nexus2', 
protocol: 'http', 
repository: 'NexusArtifactUploader', 
version: '2.4'

您可以从管道片段生成器生成上述语法。

答案 1 :(得分:0)

就我而言,使用 Nexus Jenkins插件${artifactName}.jar${artifactName}-sources.jar工件部署到同一Nexus目录时出现问题。

问题出在相同的包装类型(jar)上,这就是为什么无法将这些工件上传到Nexus的原因:插件都将文件名都更改为${artifactId}-${version}.${packaging},但出现了错误:

  

上传组件失败(服务器发出400响应)

通过为classifier工件提供-sources.jar来解决此问题:

stage('Publish') {
    def pom = readMavenPom file: 'pom.xml'
    nexusPublisher nexusInstanceId: 'your-nexus-instance-id', \
        nexusRepositoryId: 'your-nexus-repository-id', \
        packages: [[$class: 'MavenPackage', \
        mavenAssetList: [[classifier: '', extension: '', filePath: "target/${pom.artifactId}-${pom.version}.${pom.packaging}"], \
                         [classifier: 'sources', extension: '', filePath: "target/${pom.artifactId}-${pom.version}-sources.${pom.packaging}"]], \
        mavenCoordinate: [artifactId: "${pom.artifactId}", \
        groupId: "${pom.groupId}", \
        packaging: "${pom.packaging}", \
        version: "${pom.version}-${env.BUILD_NUMBER}"]]]
}