What is CI/CD⁉️
Continuous Integration (CI) automates merging code changes from various developers into a single codebase. Developers frequently commit to a central repository (like Github), where automated tools build and review code. CI aims to spot and fix bugs faster, simplify teamwork, enhance software quality, and speed up new feature releases.
Continuous Delivery (CD) follows Continuous Integration, ensuring prompt and error-free delivery of new changes to customers. It involves staging tests, akin to the production environment, to prevent release failures. CD automates releases, maintaining a deployment-ready product for anytime application deployment.
What Is a Build Job⁉️
In Jenkins, a build job is a defined task that automates the compilation, testing, and packaging of source code into a deployable artifact. It's a crucial part of the Continuous Integration process, where Jenkins pulls code changes from a repository, triggers the build, and generates executable software, ensuring consistent and reliable results with each commit.
Types Of Jobs ⁉️
Jenkins offers various types of build jobs which are given below:-
Freestyle Project: Basic graphical build setup with manual configuration flexibility.
Pipeline:** Powerful scripting for complex, adaptable build processes.
Multibranch Pipeline: Automates separate pipelines for various code branches.
Parameterized Build: Customizes builds based on user-provided parameters.
Scheduled Build: Automates tasks at predefined times or recurring intervals.
GitHub Organization: Automates GitHub project integration and creation.
Distributed Build: Distributes tasks across agents for faster, efficient builds.
Task 1:
Set up a Jenkins agent for your app, then create a new freestyle project to automate building and running a Docker container: add a docker build
step to create the image, and a second step to run the container using the image.
Creating the agent for app
Access your Jenkins dashboard through a web browser.
Navigate to "Manage Jenkins" and then select "Manage Nodes and Clouds." In this section, you'll be able to create a new agent for your Jenkins setup.
Set Up a New Agent:
Click on the "New Node" option.
Give a suitable name to the agent (e.g., "Docker-Agent").
Select "Permanent Agent" and then click "OK."
Agent Configuration:
Define the number of executors (simultaneous build processes) for the agent.
Select the suitable launch method. For simplicity, you can opt for "Launch agent by connecting it to the master."
Save the Configuration: Click "Save" to finalize the new agent setup.
Setting Up a Jenkins Freestyle Project
Login to Jenkins: Access your Jenkins dashboard using a web browser.
Create a New Project: Click on "New Item" to create a new project.
Choose Project Type: Select "Freestyle project" as the project type and provide a name for your project.
Configure Source Code Management: In the project configuration, specify details like the source code repository URL and the branch to build.
Define Build Steps: Under the "Build" section, add build steps such as executing shell commands or running scripts required for your project.
docker build . -t django-app docker run -d -p 8001:8001 django-app:latest
Save and Build: Click "Save" to create the project. You can manually trigger builds using the "Build Now" button.
View Console Output: Once the build starts, you can monitor the progress and view detailed logs in the console output.
😁😁
Task 2:
Create a Jenkins project to launch multiple containers using docker-compose up -d
, and include a cleanup step to stop and remove containers with docker-compose down
command.
All the step are same just the execute shell script will changes.
echo "code cloned"
docker-compose down
docker-compose up -d --no-deps --build web
echo "code deploy"
Console output:
Conclusion
In the world of DevOps, CI/CD revolutionizes software development. Continuous Integration (CI) automates code merging, while Continuous Delivery (CD) ensures seamless delivery to customers. Jenkins, a powerful tool, offers various build job types for efficient development workflows.
As part of your DevOps journey:
Set Up Agent and Freestyle Project: Create a Jenkins agent for your app and build a freestyle project. Automate Docker container building and running.
Create Dockerized Project: Launch multiple containers using Jenkins and docker-compose up -d, ensuring easy project management.
Let's Connect:
| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|
------- Let's connect! -------
|_____________|
............... \ (•◡•) / ...................
................. \ ...... / .....................
.................. ——- .......................
.................. | ... | ......................
.................. |_ . |_ ....................
Thank you for exploring my blog! Your interest is truly appreciated. 🙌