Jenkins Declarative CI/CD Pipeline (Notes App)
This HandsOn will help you learn how to implement continuous integration and continuous deployment using declarative pipeline and deploy using Docker Container.
Perquisites -
Jenkins Docker
Git Repository URL :
https://github.com/Bhushan0151/django-notes-app.git
Create EC2 Instance and install the Jenkins & Docker on the Server.
for the Installation of the Jenkins And Docker Please follow the Official Document.

Step1 : On the Dashboard-> Select New Item -> enter the name of the project -> Select the Pipeline -> then ok

Step 2 - Write a description of the Project -> Click on the GitHub Project and the paste git repo link over there

Step 3 - Build Trigger -> Click on the GitHub Hook Trigger polling
GitHub Hook Trigger polling- Which is use for the , when we/anybody can changes the Done on the GitHub , Which will reflect on the pipeline it will trigger.

Step 4 - Create the Declarative Pipeline using Groovy Syntax
Using this Script we can run our pipeline-
Explanation of the script -
Here All the stages are the agents of the pipeline. so using these stages we can build our pipeline.
stage1 : Clone Code - these stage use for cloning the code of our repository,
stage2 : Build Image - These stage is use for Building the code for making the Docker Image. using these Docker Image we can Deploy these code on the docker Container and after deploying it will accusable on the browser.
Stage 3 : Push to Docker Hub - Using these stage , after Building the code , we can push the image on the docker hub , for pushing the image, we need to login on the docker , and tagging the image and push on the docker hub, for all of these task we use these stage. Also need to add credentials on the manage Jenkins -> global tool configuration using adding the credentials .
stage 4 : Deploy Container - These stage is use for the deploying the container , using the Docker image, which is we build in the previous stages.
Pipeline
pipeline {
agent any
stages {
stage("Clone Code") {
steps {
echo "Cloning the code"
git url: "https://github.com/LondheShubham153/django-notes-app.git", branch: "main"
}
}
stage("Build Image") {
steps {
echo "Building the Docker image"
sh "docker build -t node-app ."
}
}
stage("Push to Docker Hub") {
steps {
echo "Pushing the Docker image to Docker Hub"
withCredentials([usernamePassword(credentialsId: 'dockerHub', passwordVariable: 'dockerHubPass', usernameVariable: 'dockerHubUser')]) {
sh "docker tag node-app:latest ${env.dockerHubUser}/node-app:bhushan"
sh "docker login -u ${env.dockerHubUser} -p ${env.dockerHubPass}"
sh "docker push ${env.dockerHubUser}/node-app:bhushan"
}
}
}
stage("Deploy Container") {
steps {
echo "Deploying the container"
// Use the appropriate steps or scripts to deploy the container
sh "docker run -d -p 8000:8000 bhushann11/node-app:bhushan"
}
}
}
}

Stage View of the Pipeline

Console Output of the Pipeline

Docker Image push on the Docker Hub

My Notes App Running On the Port 8000

Last updated