Table of contents
- Introduction
- Continuous Integration (CI)
- Continuous Delivery (CD)
- Build Job
- Freestyle Projects in Jenkins
- Task-01: Setting up a Jenkins Freestyle Project for Docker Applications
- Task-02: Setting up Jenkins Project for Docker Compose Applications
- Thanks for tuning in! ๐ Wishing you an enjoyable learning experience ahead!
This is#90DaysofDevopschallenge under the guidance ofShubham Londhesir.
Introduction
Welcome to Day 23 of our #90daysofdevops adventure! Today's task focuses on exploring the capabilities of Jenkins Freestyle Projects to boost your DevOps skills. Let's get started!
Continuous Integration (CI)
CI involves automating the integration of code changes made by multiple developers into a shared code repository like GitHub. With CI, developers frequently commit their code changes, triggering automated processes that build the code, perform tests, and review the changes for errors. The main goals of CI are to detect and fix bugs quickly, simplify collaboration among developers, enhance software quality, and accelerate the release of new features.
Continuous Delivery (CD)
CD extends CI by ensuring that new changes can be released to customers rapidly and without errors. After successful integration through CI, CD involves running additional tests, including integration and regression tests, in a staging environment similar to the production environment. This ensures that the final release is stable and functional. CD also automates the release process, ensuring that the software is always ready for deployment, enabling teams to deploy the application at any time.
Build Job
A build job in Jenkins represents the configuration for automating specific tasks or steps in the software building process. These tasks include tasks like managing dependencies, compiling code, archiving files, and testing code in various environments.
Freestyle Projects in Jenkins
Freestyle projects in Jenkins provide developers with a flexible environment to build, test, and deploy software using a range of configuration options. In a Jenkins freestyle project, developers can define tasks such as building, testing, and deploying code, all while leveraging Jenkins' versatility and ease of use. Freestyle projects offer developers the freedom to customize their build and deployment processes according to their project requirements and preferences.
Task-01: Setting up a Jenkins Freestyle Project for Docker Applications
Set up an agent for your application:
Log in to your Jenkins instance.
Navigate to "Manage Jenkins" > "Manage Nodes and Clouds" > "New Node."
Configure a new node with necessary details like name, description, and launch method (typically SSH).
Provide connection details such as host, credentials, and labels.
Save the configuration.
Next, activate your agent from the remote directory.
Now, our agent is connected.
Create a new Jenkins Freestyle Project:
From the Jenkins dashboard, click on "New Item" to create a new project.
Enter a name for your project and select "Freestyle project."
Click "OK" to proceed.
Configure the Build Section:
Scroll down to the "Build" section of your project configuration.
Click on "Add build step" and select "Execute shell" (assuming you're working on a Unix-like system).
Build the Docker Image:
In the "Execute shell" build step, enter the command:
docker build -t <image_name>:<tag> .
- Replace
<image_name>
and<tag>
with appropriate values for your Docker image.
- Replace
This command builds the Docker image using the Dockerfile present in the project directory.
Run the Docker Container:
Add another build step by clicking on "Add build step" and selecting "Execute shell."
Enter the command:
docker run -d -p <host_port>:<container_port> <image_name>:<tag>
Replace
<host_port>
and<container_port>
with the appropriate port mappings.Ensure to use the same image name and tag used during the build step.
Save and Apply Changes:
Review your project configuration to ensure correctness.
Click on "Save" to apply the changes.
Task-02: Setting up Jenkins Project for Docker Compose Applications
Create a Jenkins Project:
- Repeat the process of creating a new Jenkins project as outlined in Task-01.
Configure the Build Section:
In the project configuration, add a build step and select "Execute shell."
Enter the command:
docker-compose up -d
This command starts the containers defined in the docker-compose file in detached mode.
Cleanup Step:
Add another build step for cleanup purposes.
Enter the command:
docker-compose down
This command stops and removes the containers defined in the docker-compose file.
Save and Apply Changes:
Review and confirm your project configuration.
Click on "Save" to finalize the setup.
By following these step-by-step instructions, you'll be able to effectively create Jenkins Freestyle Projects for Docker applications and Docker Compose environments, facilitating seamless automation in your DevOps workflow.