Continuous delivery

Now that you are a committer machine, let's go to the next level and make your application ready to deploy whenever you want.

First, you'll need your just-built artifact to be available in a proper repository. This is when we use Sonatype Nexus.

I won't go into the setup details in this book. One easy way to do it is by using Docker containers. You can see more information about it at, https://hub.docker.com/r/sonatype/nexus/.

Once your Nexus is available, you need to go to the pom.xml file and add this configuration:

    <distributionManagement>
<repository>
<id>Releases</id>
<name>Project</name>
<url>[NEXUS_URL]/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>

Now instead of building, just use the following:

mvn

You'll do so like this:

mvn deploy

So once your artifact is built, Maven will upload it to Sonatype Nexus. Now it is properly stored for future deployment.

Now you are almost ready to dance to the automation song. Let's bring Jenkins to the party.

As mentioned for Nexus, I will not get into the details about setting up Jenkins. I also recommend you do it using Docker. See the following link for details:

https://hub.docker.com/_/jenkins/

If you have absolutely no idea on how to use Jenkins, please refer to this official guide:

https://jenkins.io/user-handbook.pdf

Once your Jenkins is up and running, you'll create two jobs:

  1. Your-Project-Build: This job will be used to build your project from the source code.
  2. Your-Project-Deploy: This job will be used to deploy your artifact after being built and stored in Nexus.

You will configure the first one to download the source code of your project and build it using Maven. The second will download it from Nexus and deploy to the application server.

Remember that the deployment process involves some steps in most cases:

  1. Stop the application server.
  2. Remove the previous version.
  3. Download the new version from Nexus.
  4. Deploy the new version.
  5. Start the application server.

So you'd probably create a shell script to be executed by Jenkins. Remember, we are automating, so no manual processes.

Downloading the artifact can be a little tricky, so maybe you could use something like this in your shell script:

wget --user=username --password=password "[NEXUS_URL]/nexus/service/local/artifact/maven/content?g=<group>&a=<artifact>
&v=<version>&r=releases"

If everything goes fine until this point, then you'll have two buttons: one for building and another for deploying. You are ready and set to build with no need to use any IDE to deploy, and no need to touch the application server.

Now you are sure that both processes (build and deploy) will be executed exactly the same way every time. You can now plan them to be executed in a shorter period of time.

Well, now we will move to the next and best step: continuous deployment.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.2.225