3.2 Pipeline CI/CD — GitHub, Maven, Jenkins, Artifactory, SonarQube, Docker, Tomcat, Kubernetes ( Pods and Services)
This is the continuation to the Previous Post 3.1 Pipeline CI/CD — GitHub, Maven, Jenkins, Artifactory, SonarQube, Docker, Tomcat, Kubernetes ( Pods and Services)
- Breaking the Code:
Link to the Jenkins File — Click
Jenkins Pipeline Style: Declarative Jenkins Pipeline
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.
Set the Environment of SonarQube scanner tool name as mentioned in the Jenkins — Global Tool Configuration ( Refer Screenshot Fig1.2) above.
- 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.
- In the Screenshot above Fig1.4, the docker image is build and pushed to the Docker Hub.
- 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)
- 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 pod.yml and create the new file called changed-pod.yml
> We are connecting to the Kubernetes Master through the SSH Agent Authentication.
> We are running the changed-pod.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.
Conclusion:
We have integrated the Jenkins with the Kubernetes Cluster using the SSH Agent and made the Kubernetes master to spin the Pods and Services as a part of the container orchestration.
I hope this guide helped you! Enjoy Learning and have fun!!! 😊😊