Day24 of #90DaysOfDevOps Challenge

Jenkins CI/CD Project

❄️Project:

Containerise and deploy a node.js application using Jenkins Job.

🔹Step 1

Fork the repo - https://github.com/Aishwarya-Portfolio/node-todo-cicd

🔹Step 2

Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration.

We can use SSH keys or PAT tokens to integrate the GitHub repo into Jenkins.

Here I am using SSH keys.

  1. Generate SSH key pair in your Jenkins instance.
ssh-keygen

I already have the key pair.

No alt text provided for this image

2. Create a new SSH key in GitHub and save the public key of Jenkins Instance.

No alt text provided for this image

No alt text provided for this image

3. Save the Private key in Jenkins credential.

No alt text provided for this image

No alt text provided for this image

4. Create a new Freestyle Jenkins Job -

No alt text provided for this image

5. Add source code GitHub Repo with added credential -

No alt text provided for this image

6. Now run the pipeline to check if the source code is checked out through Jenkins -

No alt text provided for this image

The repo files are present in Jenkins Workspace -

No alt text provided for this image

7. Now we need to set up a webhook for an automatic trigger from GitHub.

-- Install the GitHub integration plugin in Jenkins.

No alt text provided for this image

-- Create a Webhook.

The payload URL should be in the below format

http://jenkins_URL/github-webhook/

No alt text provided for this image

8. Do not forget to open port 8080 to Anywhere so that the GitHub webhook can reach Jenkins on port 8080.

The green tick shows that the connection is established.

No alt text provided for this image

9. In your Jenkins Job, enable GitHub Hook to trigger in the build trigger section.

No alt text provided for this image

10. To test the webhook, make some changes to the code and commit it.

Check if the Job was triggered by a push event.

No alt text provided for this image

🔹Step 3

In the Execute shell run the application using Docker compose.

  1. Create a Dockerfile to install all the dependencies and containerize the application.

No alt text provided for this image

2. Add a build step - Execute shell to build the docker image.

No alt text provided for this image

3. Docker image is created successfully.

No alt text provided for this image

No alt text provided for this image

4. Create a docker-compose file to run the container using this image.

No alt text provided for this image

5. Add the docker-compose up command to run the container.

No alt text provided for this image

6. The build is successful.

No alt text provided for this image

7. The container is up and running.

No alt text provided for this image

8. Since I want to run the application on Port 8100, I made changes in the app.js file.

No alt text provided for this image

9. Now my application is running.

No alt text provided for this image


Thank You for Reading! 📘