๐Ÿ› Day 23 - Jenkins Freestyle Project for DevOps Engineers.

ยท

5 min read

๐Ÿ› Day 23 - Jenkins Freestyle Project for DevOps Engineers.

What is CI/CD?

CI/CD stands for Continuous Integration and Continuous Delivery (or Continuous Deployment). It's a set of principles and practices in software development aimed at delivering code changes more frequently and reliably.

  • Continuous Integration (CI) is the practice of frequently integrating code changes into a shared repository. Each integration is verified by automated build and test processes, allowing teams to detect and fix problems early.

  • Continuous Delivery (CD) is the practice of automatically building, testing, and preparing code changes for deployment to production. With continuous delivery, every change that passes automated tests can be deployed to a production-like environment, where it's ready to be released to customers at any time.

  • Continuous Deployment (CD) goes one step further by automatically deploying every change that passes through the pipeline to production, without human intervention. This practice is more common in environments where rapid and frequent releases are essential.

Together, CI/CD helps teams deliver code changes more frequently, with less risk and manual effort, enabling faster time to market and better overall software quality.

What Is a Build Job?

A build job is a specific task within a Continuous Integration (CI) system that involves compiling source code, running tests, and preparing the application for deployment. It is a fundamental part of the CI process, where developers push code changes to a shared repository, triggering automated build jobs to ensure that the changes integrate correctly with the existing codebase and do not introduce any new issues.

The build job typically includes the following steps:

  1. Checking out code: The CI system retrieves the latest code from the repository to begin the build process.

  2. Compiling code: The source code is compiled into executable code, such as binaries or libraries, depending on the programming language and build tools used.

  3. Running tests: Automated tests, including unit tests, integration tests, and possibly other types of tests, are executed to verify that the code changes function as expected and do not break existing functionality.

  4. Generating artifacts: After the code is compiled and tests pass, the CI system generates artifacts, such as deployable packages or containers, that are ready for deployment to different environments.

  5. Reporting: The CI system provides feedback on the build job, including test results, code coverage metrics, and any other relevant information, to help developers identify and address issues.

By automating these processes, build jobs help streamline the software development lifecycle, enabling teams to deliver high-quality code more efficiently and reliably.

What is Freestyle Projects ?

Freestyle Projects is a feature in Jenkins, which is an open-source automation server widely used for Continuous Integration (CI) and Continuous Delivery (CD) pipelines. In Jenkins, a Freestyle Project is a flexible and customizable way to create build jobs without needing to write complex scripts or configure pipelines.

With Freestyle Projects, users can configure various build steps, such as checking out source code from version control, compiling code, running tests, and deploying artifacts. The configuration is done through a web interface, where users can add build steps, configure triggers, set up post-build actions, and define build parameters.

Freestyle Projects are called "freestyle" because they provide a lot of freedom and flexibility in how build jobs are configured and executed. However, they are also more manual and require more configuration compared to Jenkins Pipeline, which allows for defining build pipelines as code.

Overall, Freestyle Projects are a simple and effective way to get started with Jenkins and build automation, especially for users who prefer a graphical user interface (GUI) for job configuration.

Task-01: Creating an Agent and Freestyle Project for Dockerized Apps

In the ever-evolving landscape of software development, the efficient deployment and management of applications are paramount. In this tutorial, we'll explore Task-01, focusing on creating an agent for your Dockerized app and setting up a Jenkins freestyle project to automate Docker operations.

Step 1: Create an Agent for Your App

Assuming you've deployed your application using Docker, the first step is to create an agent to manage subsequent tasks. An agent in Jenkins acts as a computational resource capable of running tasks on behalf of the master Jenkins instance.

  1. Open Jenkins and navigate to "Manage Jenkins" > "Manage Nodes and Clouds."

  2. Click on "New Node" to create a new agent. Configure the agent details, specifying the connection details and labels as needed.

  3. Save the configuration to add the agent.

Step 2: Create a Freestyle Project

Now, let's set up a Jenkins freestyle project to automate the building and running of your Dockerized app.

  1. From the Jenkins dashboard, click on "New Item" to create a new project.

  2. Enter a project name and choose the "Freestyle project" option.

  3. In the project configuration, go to the "Build" section.

Step 3: Add Build Steps for Docker Operations

In the "Build" section of the project configuration, we'll add two build steps:

Build Step 1: Docker Build

Add a build step to execute the "docker build" command, constructing the image for the container.

docker build -t your-app-image .

Make sure to replace "your-app-image" with the actual name you want for your Docker image.

Build Step 2: Docker Run

Add a second build step to run the "docker run" command, starting a container using the image created in the previous step.

docker run -d --name your-app-container -p 8080:80 your-app-image

Replace "your-app-container" and "your-app-image" with your preferred container and image names.

Save the project configuration.

Task-02: Orchestrating Containers with Docker-Compose

Step 1: Create Jenkins Project for Docker-Compose

In Task-02, we'll create a Jenkins project to handle the orchestration of multiple containers defined in a Docker Compose file.

  1. Follow the steps outlined in Task-01 to create a new freestyle project in Jenkins.

  2. In the project configuration, navigate to the "Build" section.

Step 2: Add Build Steps for Docker-Compose Operations

Build Step 1: Docker-Compose Up

Add a build step to execute the "docker-compose up -d" command, initiating the deployment of multiple containers defined in the compose file.

docker-compose up -d -f path/to/your/docker-compose-file.yml

Ensure to replace "path/to/your/docker-compose-file.yml" with the actual path to your Docker Compose file.

Build Step 2: Cleanup with Docker-Compose Down

To ensure a clean environment, set up a cleanup step in the Jenkins project.

Add a build step to run the "docker-compose down" command, stopping and removing the containers defined in the compose file.

docker-compose down -f path/to/your/docker-compose-file.yml

Replace "path/to/your/docker-compose-file.yml" with the correct path.

Save the project configuration.

I think this blog will be quite valuable, offering unique viewpoints and introducing new and engaging ideas. ๐Ÿ™

๐Ÿ˜Š Happy learning!

Did you find this article valuable?

Support Pratik R. Mandge by becoming a sponsor. Any amount is appreciated!

ย