Interview Prep/Jenkins/Integrations: SonarQube, Nexus, Artifactory, Docker, Trivy

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.

All Jenkins questions Roadmap: Jenkins

More on Integrations: SonarQube, Nexus, Artifactory, Docker, Trivy