Hey DevOps enthusiasts! The #90DaysOfDevOps journey is in full swing, and today's challenge is an exciting one! We'll be diving into creating a Jenkins Freestyle Project, a fantastic opportunity to showcase your skills and push your limits. Who's ready to make it happen? ๐
What is CI/CD?
Continuous Integration (CI)
Continuous Integration (CI) is all about automating the integration of code changes from multiple developers into a single codebase. Imagine developers frequently committing their work into a central repository like GitHub. Automated tools then kick in to build the newly committed code and perform tasks like code review. The main goals of CI are:
Quickly find and address bugs ๐
Make the integration process smoother for the team
Improve software quality ๐
Reduce the time to release new features ๐
Continuous Delivery (CD)
Continuous Delivery (CD) takes CI a step further. It ensures that new changes can be released to customers quickly and without errors. This involves running integration and regression tests in a staging environment to ensure the final release is stable. CD automates the release process, ensuring that the product is always ready for deployment. This means we can deploy at any moment with confidence!
What is a Build Job?
A Jenkins build job is a configuration for automating specific tasks or steps in the application building process. These tasks can include:
Gathering dependencies ๐ฆ
Compiling code ๐ ๏ธ
Archiving artifacts ๐๏ธ
Running tests โ
Deploying code to different environments ๐
Jenkins supports several types of build jobs, including freestyle projects, pipelines, multi-configuration projects, folders, multibranch pipelines, and organization folders.
What is a Freestyle Project? ๐ค
A freestyle project in Jenkins is a type of project that allows you to build, test, and deploy software using various options and configurations. It's incredibly flexible and user-friendly. Let's look at a couple of tasks you can accomplish with a freestyle project.
Task 1: Docker Deployment with a Freestyle Project
Step 1: Create an Agent for Your App
Ensure Jenkins Node has Docker Installed:
- Your Jenkins node (agent) needs to have Docker installed. If Docker isn't installed, you can install it by following the instructions on the Docker website.
Step 2: Create a New Jenkins Freestyle Project
Navigate to Jenkins Dashboard:
- Open your Jenkins dashboard in your web browser.
Create a New Item:
Click on "New Item" on the left sidebar.
Enter a name for your project (e.g., "Todo-App-Deployment").
Select "Freestyle project".
Click "OK" to create the project.
Step 3: Configure Build Steps
Add Build Step to Build Docker Image:
In the project configuration page, scroll down to the "Build" section.
Click on "Add build step" and select "Execute shell".
Enter Docker Build Command:
In the command box, enter the following command to build the Docker image:
docker build -t your-app-image-name .
This command builds a Docker image with the tag
your-app-image-name
using the Dockerfile in the current directory.
Add Build Step to Run Docker Container:
Click on "Add build step" again and select "Execute shell".
Enter the following command to run the Docker container:
docker run -d --name your-container-name your-app-image-name
This command runs a Docker container in detached mode (
-d
) with the nameyour-container-name
using the imageyour-app-image-name
.
Save the Project:
- Click "Save" to save the project configuration.
Example Configuration
# Step 1: Build the Docker image
docker build -t todo-app .
# Step 2: Run the Docker container
docker run -d --name todo-app-container todo-app
Task 2: Running Docker Compose with a Freestyle Project
Step 1: Create a Jenkins Project for Docker Compose
Navigate to Jenkins Dashboard:
- Open your Jenkins dashboard in your web browser.
Create a New Item:
Click on "New Item" on the left sidebar.
Enter a name for your project (e.g., "Todo-App-Compose").
Select "Freestyle project".
Click "OK" to create the project.
Step 2: Configure Build Steps
Add Build Step to Run Docker Compose Up:
In the project configuration page, scroll down to the "Build" section.
Click on "Add build step" and select "Execute shell".
Enter Docker Compose Up Command:
In the command box, enter the following command to start the services defined in the
docker-compose.yml
file:docker-compose up -d
This command starts all the services defined in your Docker Compose file in detached mode (
-d
).
Step 3: Configure Cleanup Step
Add Post-Build Action for Cleanup:
Scroll down to the "Post-build Actions" section.
Click on "Add post-build action" and select "Execute shell".
Enter Docker Compose Down Command:
In the command box, enter the following command to stop and remove the services defined in the
docker-compose.yml
file:docker-compose down
Save the Project:
- Click "Save" to save the project configuration.
Example Configuration
# Step 1: Start containers with Docker Compose
docker-compose up -d
# Cleanup step to stop and remove containers
docker-compose down
Conclusion
Creating a Jenkins Freestyle Project is a fantastic way to automate your build, test, and deployment processes. Whether you're building Docker images or managing containers with Docker Compose, freestyle projects offer the flexibility and simplicity needed to get the job done efficiently.
Keep pushing your limits, DevOps community! Let's continue to learn, grow, and innovate together. Happy coding! ๐
Feel free to share your experiences and challenges in the comments below. Let's make this #90DaysOfDevOps journey a memorable one! ๐