How to deploy multiple artifacts to nexus?
Please find the below syntax for the nexusArtifactUploader in Jenkinsfile.
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'
You can generate the above syntax from the pipeline snippet generator.
In my case there was a problem with deploying ${artifactName}.jar
and ${artifactName}-sources.jar
artifacts to the same Nexus directory using Nexus Jenkins Plugin.
The problem was with the same packaging type (jar
), that's why these artifacts couldn't be uploaded to Nexus: plugin changes both provided file names to ${artifactId}-${version}.${packaging}
and I've got the error:
Upload component was unsuccessful (400 response from server)
Fixed the issue by providing classifier
for -sources.jar
artifact:
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}"]]]}