How do you deploy Maven artifacts to Nexus from Jenkins?
IntermediateConceptIntegrations: SonarQube, Nexus, Artifactory, Docker, Trivy
Answer
Define repositories in pom.xml distributionManagement (releases and snapshots), and provide credentials in a settings.xml with matching <server><id>. Supply settings.xml from the Config File Provider plugin or generate it from credentials:
withCredentials([usernamePassword(credentialsId: 'nexus-deployer', usernameVariable: 'NX_USER', passwordVariable: 'NX_PASS')]) {
sh 'mvn -B -s ci/settings.xml deploy -DskipTests'
}
where ci/settings.xml uses <username>${env.NX_USER}</username> and <password>${env.NX_PASS}</password>. Releases repositories typically disallow redeploy, so re-running a release build fails by design.
More on Integrations: SonarQube, Nexus, Artifactory, Docker, Trivy
How do you integrate SonarQube with a Jenkins pipeline?IntermediateHow does `waitForQualityGate` work?IntermediateHow do you publish npm packages or pull dependencies through Nexus or Artifactory?BeginnerHow do you use JFrog Artifactory from Jenkins?IntermediateHow do you build and push a Docker image from Jenkins on a VM agent?BeginnerHow do you scan an image with Trivy in a pipeline and gate on results?Intermediate