Day 23 : Jenkins Freestyle Project for DevOps Engineers.
In the fast-paced world of DevOps, continuous integration and continuous deployment (CI/CD) have become indispensable practices. These methodologies streamline the development process by automating the building, testing, and deployment of code, ensuring rapid and reliable software delivery. At the heart of this process lies tools like Jenkins, which provide a robust platform for automating various stages of software development. In this blog post, we'll delve into Jenkins Freestyle Projects, a versatile feature that empowers DevOps engineers to automate their workflows effectively.
CI/CD: Streamlining Software Delivery
Before diving into the specifics of Jenkins Freestyle Projects, let's briefly touch upon CI/CD. CI/CD is a set of practices aimed at automating the process of integrating code changes into a shared repository (CI) and continuously delivering them to production environments (CD). By automating tasks such as building, testing, and deployment, CI/CD pipelines ensure that software changes are reliably and efficiently delivered to end-users.
Understanding Build Jobs
At the heart of CI/CD pipelines are build jobs. A build job is a task that executes a series of commands or scripts to compile, test, and package the codebase into a deployable artifact. These artifacts could be binaries, container images, or any other form of executable code. Build jobs are crucial components of CI/CD pipelines as they automate the process of transforming source code into deployable software.
Exploring Freestyle Projects in Jenkins
Now, let's explore Freestyle Projects in Jenkins. Freestyle Projects offer a flexible and customizable way to create automated build and deployment pipelines. Unlike other Jenkins project types that are more structured, Freestyle Projects allow developers and DevOps engineers to define custom build steps and configurations tailored to their specific requirements.
Task-01: Building and Deploying Docker Containers
To illustrate the capabilities of Jenkins Freestyle Projects, let's consider a scenario where we need to build and deploy Docker containers using Jenkins.
Configure Agent:
Log in to your Jenkins dashboard.
Click on "Set up an agent" to create a new project.
Enter the "Node Name" then select "Permanent Agent" and click on "Create"
Configure Node Details:
Enter a description for the node (optional).
Specify the number of executors. Executors determine how many concurrent builds the node can handle.
To determine the root directory of a remote EC2 instance, access the instance and execute the command "pwd". This command displays the present working directory, indicating the root directory of the system.
Enter a "Labels" name and click "save".
Create a Jenkins Freestyle Project:
Click on "Create a job" to create a new project.
Enter a name for your project (e.g., "ToDo-Dev").
Select "Freestyle project" and click "OK" to create the project.
Configure Build Steps:
Scroll down to the "Build" section of the project configuration.
Click on "Add build step" and select "Execute shell".
In the command box, enter the Docker build command to build the image for your container.
docker build . -t todo-dev
In the command box, enter the Docker run command to start a container using the image created.
docker run -d -p 8080:8000 todo-dev
Adjust the port mappings (
-p
) and other options as needed for your application.Click on "Save" to save the configuration of your Jenkins project.
Click on "Build Now" to trigger a build of your pipeline.
Now, when you trigger a build for this Jenkins project, it will execute the specified Docker build and run commands, effectively building and running your Docker container. Make sure that Jenkins has appropriate permissions to execute Docker commands on the machine where it is running.
Conclusion
Jenkins Freestyle Projects provide DevOps engineers with a powerful toolset to automate various aspects of the software development lifecycle. By leveraging Jenkins to build and deploy Docker containers, teams can streamline their CI/CD pipelines and accelerate the delivery of high-quality software. With the flexibility and customization options offered by Freestyle Projects, developers can tailor their automation workflows to suit the unique requirements of their projects, ultimately driving efficiency and innovation in the DevOps ecosystem.
I'm confident that this article will prove to be valuable, helping you discover new insights and learn something enriching .
thank you : )
Subscribe to my newsletter
Read articles from Prathmesh Vibhute directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by