From To-Do to Done: Accelerating Productivity with Jenkins-Agent Deployment of Notes App!

From To-Do to Done: Accelerating Productivity with Jenkins-Agent Deployment of Notes App!

ยท

4 min read

Prerequisites

  1. Basics should be known of Linux, Git, GitHub, Docker, Jenkins, and AWS.

  2. Knowledge about the building of jobs on agents in Jenkins.

New to setting up Jenkins master-agent connection? No worries! Click here to get step-by-step guidance and master the process with ease.

Jenkins is written in Java, so we need to install Java on the agent's host for a reliable connection.

Forking and Cloning the Project

  1. Fork this Repository.

  2. Clone it to your system.

Throughout this project, I've utilized the AWS EC2 instance. If you're keen to learn about setting up your own AWS EC2 Instance, Click here for a beginner-friendly guide.

Setting Up the Agent Node on Jenkins

The agent will establish a seamless connection with the Jenkins master through SSH. Check the status of the agent on the dashboard whether it is in sync or not.

With the agent setup complete, it's time to delegate a job to it.

Creating credentials

In our project, we utilize the docker-hub login and image-pushing concept. To ensure the secure handling of passwords and usernames, we create credentials and pass them using the environment variable plugin. This ensures a safe and streamlined process when interacting with docker-hub, elevating our CI/CD workflow to new heights.

  1. Go to Dashboard, and click on Manage Jenkins.

  2. Scroll down and select the credentials.

  3. Click on Add Credentials.

  4. Select the "Username with password" option from the dropbox.

  5. Give your username and password.

  6. ID is important as this credential will be denoted by its ID. Give some description of the credential.

  7. Click on Create.

We'll be using this credential during the pipeline creation.

Creating a GitHub-Webhook

Webhooks provide a way for notifications to be delivered to an external web server whenever certain events occur on GitHub.

  1. Go to the GitHub project's repository settings.

  2. Under Code and automation select the Webhooks.

  3. Then click on Add webhook.

  4. To set up the webhook, include the master's (Jenkins) host IP in the Payload URL and add /github-webhook/ at the end. For instance, if the Jenkins IP is, http://127.0.0.1:8000 the complete Payload URL will be http://127.0.0.1:8000/github-webhook/. This allows seamless communication between Jenkins and GitHub, enabling automated builds triggered by repository events.

  5. At the end select the "Send me everything" option.

  6. Click on Add webhook.

  7. Prior to proceeding, it's essential to ensure the webhook activation. Once activated, a reassuring blue tick will appear, signifying successful activation.

Note: If you are utilizing an AWS EC2 Instance, it is essential to include port 8080's source as "Anywhere IPV4" in the "Edit inbound rules" on the master's host. By doing so, you grant necessary access to the Jenkins master.

Building a Job for the agent

  • Go to Jenkins dashboard and click on the New Item.

  • Give some Item name and select Pipeline from the choices.

  • A form will appear in front of you like this.

  • Give some description of the project.

  • Select the GitHub project checkbox if you're taking the project from GitHub. Additionally, provide the project URL in the required field.

  • In the Build Triggers section check the "GitHub hook trigger for Git SCM polling" checkbox. This helps you to be up-to-date with your GitHub project.

  • At last, select the option "pipeline script from SCM" and fill in all the fields required to proceed.

  • Select Git from SCM. Give the Repository URL along with the credential we've created above. Give the Branch Specifier(working branch on GitHub) e.g. main/master.

  • Set the Script path from the GitHub repository. In my case, the script was present externally(not in any folder) so I gave the script name like Jenkinsfile.

  • Click on save. You'll be able to see your project shining on the dashboard.

Note: To ensure smooth operation in our project, Docker and Docker-compose must be installed on the agent's host, along with the necessary permissions. Granting user permissions over Docker requires executing the following straightforward command on the agent's host sudo usermod -aG docker $USER. After that reboot the server.

Finally, it's time to build the project! Just click the 'Build Now' button, and in a matter of seconds, witness the pipeline successfully building and deploying over the agent's host IP at port 8000. Exciting times lie ahead as your CI/CD pipeline springs into action!

Node Todo Application successfully running on port 8000. ๐ŸŽ‰


Here is a link to my project ๐Ÿ”— Node-Todo-CICD

ย