Day 23: Streamline Your DevOps Workflow: Mastering Jenkins Freestyle Projects and CI/CD Pipelines
What is CI/CD?
CI/CD stands for Continuous Integration and Continuous Deployment (or Continuous Delivery). It's a process used in software development to make things easier and more efficient.
Continuous Integration (CI)
Think of Continuous Integration like a big group project in school where everyone is working on the same document. Every time someone makes changes, those changes are saved to the main document right away. In software development, CI means that every time a developer makes changes to the code, those changes are automatically tested and merged into the main codebase. This helps catch problems early and ensures that everyone's code works well together.
Continuous Deployment (CD)
Continuous Deployment takes it a step further. Imagine after updating the group project document, it's automatically printed and handed in to the teacher without any extra steps. In software development, CD means that once the code is tested and merged, it’s automatically deployed to the live environment where users can access it. This ensures that new features and fixes are delivered to users quickly.
Benefits of CI/CD
Faster Development: Code changes are tested and deployed quickly.
Fewer Bugs: Automated testing catches issues early.
Team Collaboration: Developers can work together more easily since their changes are integrated continuously.
Simple Example
Let's say you're working on a web app with a team. With CI/CD:
CI: You write a new feature and push your code. Jenkins (a CI tool) automatically runs tests to make sure your code doesn’t break anything and merges it with the main project.
CD: Once the tests pass, the new version of your app is automatically deployed to the server where users can start using the new feature right away.
In summary, CI/CD helps automate and streamline the process of integrating and deploying code changes, making software development faster and more reliable.
What is a Build Job?
A build job automates the process of creating a software application. It takes different pieces of code and combines them to make a working application.
Key Points
Automation: Compiles and assembles the code automatically.
Tools: Uses tools like Jenkins.
Steps: Includes steps like compiling code, running tests, and packaging the application.
Example in Simple Terms
Ingredients: You have pieces of code.
Steps:
Compile the code.
Run tests to ensure everything works.
Package the application.
Why It’s Important
Consistency: Builds the application the same way every time.
Efficiency: Saves time by automating tasks.
Quality: Catches errors early through automated testing.
How It Works in Jenkins
Create a Job: Name it “demoApp Build”.
Add Steps: Define steps like compiling, testing, and packaging.
Run the Job: Jenkins runs these steps automatically.
In summary, a build job automates creating and testing software, ensuring it works correctly before release.
Sure, here's a shorter version:
What is a Freestyle Pipeline?
A freestyle pipeline in Jenkins automates software tasks like compiling, testing, and deploying. It's flexible, customizable, and easy to use.
Key Points
Flexibility: Customize tasks for your project.
Automation: Automate compiling, testing, and deployment.
Ease of Use: Managed through Jenkins.
Example
Like a recipe:
Ingredients: Your code.
Steps:
Compile.
Test.
Deploy.
Benefits
Efficiency: Saves time.
Consistency: Tasks are done the same way.
Integration: Works with other tools.
How to Use
Create a Job: Set up a freestyle project.
Define Steps: Configure tasks.
Run: Trigger the pipeline.
In short, a freestyle pipeline automates software tasks, speeding up development.
Task 1:
Create an agent for your job
create a new jenkins freestyle project for your job
I have cloned the github repo https://github.com/LondheShubham153/django-todo-cicd.git
gave branch name develop as repos was the default branch name develop.
In the Build Section of the project add a build step to run the "docker build" command to build the image for the container.
Click on save and then click the Build Now Button
As you can see the Job ran successfully
and you can successfully check the job build in the following directory
sudo ls /var/lib/jenkins/workspace/
Add a second step to run the "docker run" command to start a container using the image created in step 3.
To check the port number where the container is running use docker ps
Please add a rule in your instance security group port number.
_________________________________________________________________________________________
Task 2:
Create Jenkins project to run the "docker-compose up -d" command to start the multiple containers defined in the compose file (Hint- use day-19 Application & Database docker-compose file)
Set up a cleanup step in the Jenkins project to run the "docker-compose down" command to stop and remove the containers defined in the compose file.
we have stop the previous container by docker kill container-id
and docker rm container-id
we can also check if the pipeline has worked or not through the docker ps
command
In conclusion, the Jenkins Freestyle Project empowers DevOps engineers to automate, integrate, and enhance software development. Its versatility, efficiency, and collaborative features contribute to streamlined workflows and improved software quality. Embracing this tool is crucial for modern DevOps practices, enabling agile and effective development lifecycles.
~Dipen : )