如何将多个工件部署到 nexus?
How to deploy multiple artifacts to 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 中制作它??
请在 Jenkinsfile 中找到 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'
您可以从管道片段生成器生成上述语法。
在我的案例中,使用 Nexus Jenkins 插件 将 ${artifactName}.jar
和 ${artifactName}-sources.jar
工件部署到同一 Nexus 目录时出现问题。
问题出在相同的打包类型 (jar
),这就是为什么无法将这些工件上传到 Nexus:插件将提供的文件名都更改为 ${artifactId}-${version}.${packaging}
,我已经错误:
Upload component was unsuccessful (400 response from server)
通过为 -sources.jar
神器提供 classifier
解决了问题:
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}"]]]
}
我在 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 中制作它??
请在 Jenkinsfile 中找到 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'
您可以从管道片段生成器生成上述语法。
在我的案例中,使用 Nexus Jenkins 插件 将 ${artifactName}.jar
和 ${artifactName}-sources.jar
工件部署到同一 Nexus 目录时出现问题。
问题出在相同的打包类型 (jar
),这就是为什么无法将这些工件上传到 Nexus:插件将提供的文件名都更改为 ${artifactId}-${version}.${packaging}
,我已经错误:
Upload component was unsuccessful (400 response from server)
通过为 -sources.jar
神器提供 classifier
解决了问题:
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}"]]]
}