Day 24 and 25 : Complete Jenkins CI/CD Project
Table of contents
CI and CD stand for continuous integration and continuous delivery/continuous deployment. CI is a modern software development practice in which incremental code changes are made frequently and reliably. Automated build-and-test steps triggered by CI ensure that code changes being merged into the repository are reliable. The code is then delivered quickly and seamlessly as a part of the CD process. CI/CD pipeline refers to the automation that enables incremental code changes from developers’ desktops to be delivered quickly and reliably to production.
Benefits of CI/CD:
Automated testing enables continuous delivery, which ensures software quality and security and increases the profitability of code in production.
CI/CD pipelines enable a much shorter time to market for new product features.
The great increase in overall speed of delivery enabled by CI/CD pipelines improves an organization’s competitive edge.
Automation frees team members to focus on what they do best, yielding the best end products.
By moving away from traditional waterfall methods, engineers and developers are no longer bogged down with repetitive activities that are often highly dependent on the completion of other tasks.
Stages of CICD:
• Source – It focuses on source control, covering version control, and tracking changes.
• Build – It involves the creation and compiling of codes and is considered a continuous integration. In this stage, new code is integrated while quickly determining issues and conflicts, if any.
• Test – It involves automated testing of code to validate the behavior of the software. In this stage, automated tests happen in both continuous delivery and deployment.
• Deploy – It is the final phase where the package is ready to be deployed for quality assurance and production environment. This stage is automated and occurs in continuous deployment.
Task1
Fork the node-todo-app repository
-
Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration.
GitHub Webhooks: Webhooks are a method of communication that allows users to subscribe to events happening in a software system. Webhooks can be triggered whenever specific events occur on GitHub. For example, you can configure a webhook to trigger whenever:
Code is pushed to a repository
A pull request is opened
A GitHub Pages site is built
A new member is added to a team
To integrate GitHub with Jenkins job we will create a GitHub Webhook.
Go to your GitHub repository and click on Settings. Click on Webhooks and enter “<Jenkins url>//github-webhook/” as Payload URL then click on Add Webhook.
In the ‘Content type’ select: ‘application/json’.
Browse the Jenkins URL and create a new item as a freestyle project.
Add the GitHub repository URL in the GitHub project field
We have to add Jenkins credentials so that Jenkins can access the code from GitHub. To add the credentials we need to generate SSH keys from the EC2 instance.
Add the public key in GitHub, Go to Settings -> SSH and GPG keys and add the SSH key.
Add the credentials to the Jenkins project and specify the branch name.
Save the configurations and click on Build now. Check the console output and check in the EC2 instance whether the repo is cloned or not.
Task2
In the Execute shell run the application using Docker Compose.
We will dockerize the application so that it can be accessed anywhere by anyone.
As we have already cloned the repository we have a Docker-Compose file, now we have to add the build step in the Jenkins build configuration.
Once the build job is complete we can verify the app deployment by accessing the url.