
Setting Up Jenkins CI/CD As Part of GitOps Implementation
2 September, 2023
2
2
0
Contributors
👋 Introduction:
In the ever-evolving landscape of technology and software development, automation is the key to efficiency and productivity. In this blog, we delve into the world of automation with a focus on Jenkins, a powerful tool that streamlines CI/CD processes. Discover how to configure Jenkins, set up webhooks, and automate your workflows for smoother development and deployment.
🚀 Prerequisites:
- an virtual machine
- 🧐 Basic familiarity with Github , linux and Jenkins
📚 Step-by-step guide:
✒ Install Jenkins :
Please follow the steps provided in the following link to install Jenkins on your specific operating system Link
Verify that jenkins service is running by running systemctl status jenkins
Access jenkins web interface on port 8080
, password can be found by running this command sudo cat /var/lib/jenkins/secrets/initialAdminPassword
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
✒ Add GitHub and Docker Hub credentials to Jenkins:
STEP-1 Click on Manage Jenkins:
STEP-2 Click on Credentials
STEP-3 Click on System
STEP-4 Click on Add Credentials
STEP-5 Add two credentials, one for GitHub and another for Docker Hub.
✒ Jenkins Setup for DockerHub Image Updates:
Follow these steps to configure a job for testing, building, updating new image versions, and pushing them to DockerHub :
STEP-1 Create a new file in your app code repository named 'jenkinsfile.' Here's an example from my repository: link
STEP-2 Click on Add New item
STEP-3 Enter the item name 'Build-image' and select 'Pipeline'
STEP-4 Fill out below info , and click on save :
✒ Jenkins Setup for K8s manifest Updates:
Follow the steps below to add an new job that updates K8s manifest repository file with the newest image from DockerHub:
STEP-1 Create a new file in your K8s manifest repository named 'jenkinsfile.' Here's an example from my repository: link
STEP-2 Click on Add New item
STEP-3 Enter the item name 'updatemanifest' and select 'Pipeline'
STEP-4 Add a new String parameter named 'DOCKERTAG' :
STEP-5 Fill out below info , and click on save :
✒ RUN Jenkins jobs :
Run the 'Build-image' job, which will perform testing, building, and pushing the new image to DockerHub. Additionally, it should trigger the 'updatemainifestfile' job upon completion:
You may get the following error :
To fix the error we have to install 'docker-workflow' by going to "Dashboard > Manage Jenkins > Manage Plugins > Available (tab) > docker-workflow" :
Re-run the job, and it should run successfully:
Verify that the DockerHub image has been updated with the job number tag:
It should also automatically trigger the 'updatemainfest' job :
Verify that the K8s manifest repository file has been updated with the new image tag:
✒ Configure a webhook in your app's code repository :
To automate the triggering of the Jenkins job, we need to configure a webhook in our app's code repository, allowing GitHub to send webhook payloads to the Jenkins server:
✒ Conclusion:
Congratulations 🎉! You have successfully set up Jenkins CI/CD as part of the GitOps implementation. Now, when you push a change to your GitHub repository, it will automatically trigger the pipeline and deploy a new version of the app. Thank you for reading this blog
✒ Next read:
📌 Creating AWS EKS Cluster using Terraform
📌 Setting Up ArgoCD with AWS EKS for GitOps Implementation
📌 Setting Up Jenkins CI/CD as part of GitOps Implementation ( Current Blog )