Blog

The latest expert opinions, articles, and guides for the Java professional.

Pragmatic Continuous Delivery with Jenkins, Nexus and LiveRebel

Deploy- Production Job

It’s OK if you still have a ton of questions at this point – things are still far from clear. We will discuss the different requirements that will arise in real applications later, but now let’s finish our example with production deployment. We are skipping the Staging stage because there is nothing new in it compared to the ones we covered. We will come back to the QA stage later in the document.

We start by downloading the Test build (this should actually be the RC build produced by Staging):

[mvn] org.apache.maven.plugins:maven-dependency-plugin:2.4:get
-Dartifact=org.zeroturnaround:lr-
demo:B${SOURCE_BUILD_NUMBER}:war
-DremoteRepositories=cd::::ht
tp://127.0.0.1:2002/nexus/content/
repositories/test/
-Ddest=lr-demo.war

The actual deployment is very easy:

Deploy production job deploy artifacts with LiveRebel

A more interesting question is how to trigger that deployment.

One way is to use the feature provided by the Jenkins Build Pipeline plugin and add a post-build step to the automated-test job:

Deploy production job trigger deployment build pipeline plugin manually execute downstream project

Once the rest of the pipeline is complete, Jenkins will show a “Trigger” button on the deploy-production job:

Jenkins trigger button on deploy production job

Alternatively you can use the built-in Jenkins REST API and leave the button somewhere more convenient:

http://icd:2001/job/deploy-production/ buildWithParameters?SOURCE_BUILD_NUMBER=112

This also requires us to set up deploy-production as a parameterized build, with SOURCE_BUILD_
NUMBER as the parameter. A very useful feature of Jenkins is that by adding /api/ to any URL you will get a reference on what you can do with that particular entity.

Finally, LiveRebel’s Jenkins plugin provides an option to only upload the artifact without doing the deploy/update, so you can do the actual update with more control from the LiveRebel UI:

LiveRebel Jenkins plugin upload artifact deployment


Manual QA

Although automated tests are getting better and better with every year, there are still good reasons to use the ingenuity of the human mind to test the software. Thus we need to be able to incorporate a manual element in our automated workflow. Here’s how we do it.

First we set up a begin-qa job, that is triggered by automatic-test and begins the QA stage.

We start by downloading the test-notes:

[mvn] org.apache.maven.plugins:maven-dependency-plugin:2.4:get -Dartifact=org.zeroturnaround:lr-demo:B${SOURCE_BUILD_
NUMBER}:txt:build-notes -DremoteRepositories=cd::::http://127.0.0.1:2002/nexus/content/ repositories/test/ -Ddest=build.txt

Next we use the email-ext Jenkins plugin to send a customized email to the QA team (or even better, to their task manager software):

Manual QA Jenkins plugin editable email notification

Here’s the full text of the email:

We have prepared an environment for you to test:
http://host:port/lr-demo-B${ENV,var=”SOURCE_BUILD_NUMBER”}

Please test it thoroughly and IF successful click on this link:
http://host:port/job/qa-success/buildWithParameters?SOURCE_BUILD_NUMBER=${ENV,var=”SOURCE_BUILD_NUMBER”}

Note the strange syntax for inserting environment variables. Note also that we attach the test-notes to the email, thus providing the QA team with full context of the build including the name of the originator. With a bit more effort we could also insert all that information directly into the email.

It is important to correctly set up the trigger in the Advanced settings for this to work:

QA team email set up trigger in Advanced settings

The qa-success job is triggered by the link in the email as a parameterized build. It downloads the test-notes…

[mvn] org.apache.maven.plugins:maven- dependency-plugin:2.4:get -Dartifact=org.zeroturnaround:lr- demo:B${SOURCE_BUILD_NUMBER}:txt:test- notes -DremoteRepositories=cd::::ht tp://127.0.0.1:2002/nexus/content/ repositories/test/ -Ddest=qa.txt

…creates and uploads the qa-notes along with the artifact to the QA repository

echo “[QA]” >> qa.txt
echo “Manual tests passed!!!” >> qa.txt
[mvn] org.apache.maven.plugins:maven- dependency-plugin:2.4:get -Dartifact=org.zeroturnaround:lr- demo:B${SOURCE_BUILD_NUMBER}:war
-DremoteRepositories=cd::::ht tp://127.0.0.1:2002/nexus/content/ repositories/test/ -Ddest=lr-demo.war

[mvn] deploy:deploy-file
-Durl=http://127.0.0.1:2002/ nexus/content/repositories/
qa/ -DrepositoryId=cd -Dfile=lr- demo.war -Dfiles=qa.txt -Dtypes=txt -Dclassifiers=qa- notes -DgroupId=org.zeroturnaround
-Dpackaging=war -DartifactId=lr-demo -Dversion=B${SOURCE_BUILD_NUMBER}


DOWNLOAD THE PDF

No Responses

No comments yet.

RSS feed for comments on this post.

Leave a comment