4.2 Pipeline CI/CD — GitHub, Maven, Jenkins, Artifactory, SonarQube, Docker, Tomcat, Kubernetes ( Deployment and Services)

Dileep Prithvi
3 min readJun 19, 2020

--

This is the continuation to the Previous Post 4.1 Pipeline CI/CD — GitHub, Maven, Jenkins, Artifactory, SonarQube, Docker, Tomcat, Kubernetes ( Deployment and Services)

  • 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 8090

Note: Dockerfile is found here

  • In the above Screenshot Fig1.5, changed the RUN command to startup the tomcat server with the Port 8090 ( Default port is 8080)
Fig1.6
  • In the above Screenshot Fig1.6 defined the two actions

> Shell script named “replace.sh” ( Refer Fig1.7) to append the DOCKER_TAG value to the deployment.yml and create the new file called changed-deploy.yml

> We are connecting to the Kubernetes Master through the SSH Agent Authentication.

> We are running the changed-deploy.yml , services.yml in the Kubernetes Master

> Using the Try & Catch Block to catch the exceptions if any, to avoid the break of the Pipeline stages.

Fig1.7
  • Defines one or more additional steps that are run upon the completion of a Pipeline’s or stage’s run
  • Triggers the mail based up on the Success or Failure of the Build
  • Please find the below screenshot of Success Job Post action sent to the mail. ( Refer below Fig1.8)
Fig1.8

Conclusion:

We have integrated the Jenkins with the Kubernetes Cluster using the SSH Agent and made the Kubernetes master to spin the Deployment and Services as a part of the container orchestration.

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

--

--

Dileep Prithvi

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