Much ado about scripting, Linux & Eclipse: card subject to change

2017-02-24

Streamline Nexus releases with nexus-staging-maven-plugin

For years, I've had a many-step process for releasing Maven artifacts to the JBoss Nexus, which has made me reticent to do frequent releases due to the heavily manual process.
  1. Commit a change to the artifact's pom, replacing version x.y.z-SNAPSHOT with x.y.z
  2. Build the artifact in Jenkins (often triggered automatically via Github hooks) and deploy it to staging Nexus instance using server credentials in Jenkins
  3. Log into Nexus
  4. Browse for the Staging repos
  5. Sort the list by most recently updated
  6. Look for the "Implicitly created (auto staging)." entries
  7. For each entry, select the Content tab and drill down to see if that entry is the correct one (could be another job or person's staging bits)
  8. If the entry is correct, click the Close button and enter a description; if not, check the next one in the list until you find the correct one
  9. Click Refresh button
  10. Click the Release button
  11. Browse Nexus to verify the artifact is deployed

But no more! 

With the nexus-staging-maven-plugin, I can simplify that process by adding more Maven steps the job.
  1. Commit a change to the artifact's pom, replacing version x.y.z-SNAPSHOT with x.y.z
  2. Build the artifact in Jenkins (often triggered automatically via Github hooks) and deploy it to production Nexus instance using server credentials in Jenkins
  3. Browse Nexus to verify the artifact is deployed

So, how do you enable this?

  • Ensure you have all the correct metadata configured in your pom: description, URL, license, developers, SCM, issueManagement, etc. 

  • Perform three steps in Jenkins

That's it!

Or, to enable this selectively for only releases (but not SNAPSHOTS):

pom=${WORKSPACE}/path/to/pom.xml
pomVersion=$(grep "" ${pom} | head -1 | sed -e "s#.*\(.\+\).*#\1#")
MVN="/path/to/maven3/bin/mvn -Dmaven.repo.local=${WORKSPACE}/.repository/"
if [[ ${pomVersion} == *"-SNAPSHOT" ]]; then 
  ${MVN} deploy
else
  ${MVN} clean deploy -DskipRemoteStaging=true -f ${pom} \
    -DstagingDescription="[${JOB_NAME} ${BUILD_TIMESTAMP} ${BUILD_NUMBER}] :: ${pomVersion} :: deploy to local" 
  ${MVN} nexus-staging:deploy-staged -f ${pom} \
    -DstagingDescription="[${JOB_NAME} ${BUILD_TIMESTAMP} ${BUILD_NUMBER}] :: ${pomVersion} :: deploy to stage + close"
  ${MVN} nexus-staging:release -f ${pom} \
    -DstagingDescription="[${JOB_NAME} ${BUILD_TIMESTAMP} ${BUILD_NUMBER}] :: ${pomVersion} :: release"
fi

0 comments: