2.2 Pipeline CI/CD — GitHub, Maven, Jenkins, Artifactory, SonarQube, Docker, Ansible, Tomcat

Dileep Prithvi
3 min readJun 5, 2020

--

This is the continuation to the Previous Post 2.1 Pipeline CI/CD — GitHub, Maven, Jenkins, Artifactory, SonarQube, Docker, Ansible, Tomcat

  • Breaking the Code:

Link to the Jenkins File — Click

Jenkins Pipeline Style: Declarative Jenkins Pipeline

Fig1.1

In the above Screenshot Fig.1.1

  • Defined the maven and Artifactory methods globally in Jenkins File
  • Defined the method DockerTag() globally to get the latest commit ID
  • Included the options to have the timestamps and log rotation of the builds.
  • Set the tools name of Java and Maven location as mentioned in the Jenkins — Global Tool Configuration ( Refer Screenshot Fig1.2) below.
Fig1.2

Set the Environment of SonarQube scanner tool name as mentioned in the Jenkins — Global Tool Configuration ( Refer Screenshot Fig1.2) above.

Fig1.3
  • In the Screenshot above Fig1.3 explains the Artifactory, SonarQube Analysis, SonarQube Quality gate Stage.

Note: “ Quality Gate” stage is written in the Jenkins File to make the Jenkins build fail if the Sonar Quality Gate metrics is not met.

Fig1.4
  • In the Screenshot above Fig1.4, the docker image is build and pushed to the Docker Hub.
Fig1.5
  • Running the Docker Container of tomcat to port 8050

Note: Dockerfile is found here

  • In the above Screenshot Fig1.5, changed the RUN command to startup the tomcat server with the Port 8050 ( Default port is 8080)
Fig1.6
  • The above screenshot explains about the triggering of the Ansible Playbook. Please find the screenshot of the Ansible Playbook below. Refer Fig.1.6
Fig1.7
  • In the Playbook, vars is written to get the output of the latest commit ID of the Git referencing from the environment variable ‘DOCKER_TAG’ [Refer Fig1.1] in the Jenkinsfile
  • Defined the tasks to delete the previous / old containers and the images.
  • ignore_errors is mentioned in the tasks for error handling.
  • “creating docker image” task is to run the container with the tag of the latest git commit.

Conclusion:

We have integrated the Jenkins with the Ansible and made the playbook to run in the target machines. In our lab setup, the targets are the tomcat server ( created from the Docker) which is mentioned in the inventory file.

I hope this guide helped you! Enjoy Learning and have fun!!! 😊😊

--

--

Dileep Prithvi

AWS Certified Solution Architect– Associate. Skill set - AWS, DevOps