Day 23 Task: Jenkins Freestyle Project for DevOps Engineers.

ยท

9 min read

**

Index ๐Ÿ“šโœจ**

1. Introduction ๐Ÿš€

  • DevOps Essentials: CI/CD, Build Jobs, and Jenkins Freestyle Projects ๐Ÿ”„๐Ÿ’ป

2. Understanding CI/CD ๐ŸŒ

  • Overview of Continuous Integration (CI) ๐Ÿ”„

  • Extending to Continuous Deployment (CD) ๐Ÿšš

  • Significance in Modern Software Development ๐ŸŒ๐Ÿ”ง

3. Unpacking the Build Job ๐Ÿ—๏ธ

  • Role in CI/CD Pipelines ๐Ÿ”„๐Ÿ‘ท

  • Docker Context: "docker build" for Image Creation ๐Ÿณ๐Ÿ–ผ๏ธ

4. Exploring Jenkins Freestyle Projects ๐Ÿ› ๏ธ๐Ÿค–

  • User-Friendly Automation with Jenkins ๐ŸŒ๐Ÿง‘โ€๐Ÿ’ป

  • Configuring Build Steps and Project Settings โš™๏ธ๐Ÿ“

5. Today's Tasks - Docker Automation with Jenkins ๐ŸŽฏ

Task-01: Dockerize Your App ๐Ÿณ

  • Setting up a Jenkins Agent ๐Ÿ› ๏ธ๐Ÿ‘จโ€๐Ÿ’ป

  • Configuring a Jenkins Freestyle Project ๐Ÿ”„๐Ÿ—๏ธ

  • Build Steps: "docker build" and "docker run" ๐Ÿ—๏ธ๐Ÿƒ

Task-02: Docker Compose in Jenkins ๐Ÿ”„๐Ÿณ

  • Creating a Jenkins Project for "docker-compose up -d" ๐ŸŒ๐Ÿ—๏ธ

  • Cleanup Step: "docker-compose down" ๐Ÿ”„๐Ÿงน

6. Conclusion ๐ŸŽ‰๐Ÿค“

  • Recap of Key Learnings ๐Ÿ”„๐Ÿง 

  • Next Steps in Your DevOps Journey ๐Ÿš€๐Ÿ‘ฃ

**Introduction ๐Ÿš€**

Today, we're diving into the dynamic duo of Jenkins Freestyle Projects and Docker. ๐Ÿณ Unpack the power of Continuous Integration/Continuous Deployment (CI/CD) and the essence of Build Jobs. Jenkins Freestyle Projects offer a user-friendly gateway to automation. ๐Ÿ› ๏ธโœจ

Tasks:

๐Ÿ‘จโ€๐Ÿ’ป Task-01: Dockerize Your App

  1. Set up a tailored Jenkins agent.

  2. Configure a Freestyle Project.

  3. Add build steps for "docker build" and "docker run" commands.

๐Ÿ”„ Task-02: Docker Compose in Jenkins

  1. Create a Jenkins project for "docker-compose up -d."

  2. Implement a cleanup step for "docker-compose down."

** Understanding CI/CD ๐ŸŒ**

  • Continuous Integration (CI) and Continuous Deployment (CD) ๐Ÿ”„:

    • Automates integration of code changes from multiple developers into a single codebase.

    • Developers commit their work regularly to a central code repository (e.g., GitHub, Stash).

    • Automated tools handle tasks like building new code, conducting code reviews, and more upon integration.

  • Key Goals of Continuous Integration ๐Ÿš€:

    • Swiftly find and address bugs.

    • Facilitate easy code integration across a team of developers.

    • Improve software quality.

    • Reduce the time required to release new feature updates.

  • Popular CI Tools ๐Ÿ› ๏ธ:

    • Jenkins, TeamCity, Bamboo.
  • Challenges Addressed by Continuous Integration ๐Ÿ›ก๏ธ:

    • Difficulty in merging code due to prolonged isolation of developers.

    • Prone to conflicts and time-consuming merging process.

    • Accumulation of bugs identified only in later development stages.

    • Hindrance in delivering updates quickly to customers.

  • Continuous Integration Workflow ๐Ÿ”„:

    • Developers commit to a shared repository using version control systems like Git.

    • Continuous integration pipeline automates:

      • Builds.

      • Storage of artifacts.

      • Execution of unit tests.

      • Code reviews using tools like Sonar.

    • The CI pipeline is triggered with each commit/merge in the codebase for efficient development.

Continuous Delivery ๐Ÿšš

  • Production Testing Playground ๐ŸŒ:

    • Play with code in a safe environment like the real deal.

    • No last-minute surprises, catch bugs early.

  • Thorough Testing ๐Ÿงช:

    • Test everything - buttons, speed, teamwork.

    • Find and fix problems before they hit users.

  • Smooth Updates, Less Hassle ๐Ÿ”„:

    • Release with confidence, fewer risks, and costs.

    • Keeps software quality high and devs happy.

  • Ready-to-Go Code ๐Ÿš€:

    • Code ready for deployment, like a packed suitcase.

    • Happens after Continuous Integration magic.

  • Tools You Might Know ๐Ÿ› ๏ธ:

    • AWS CodeDeploy, Jenkins, GitLab.

Continuous Deployment ๐Ÿš€

  • Final Stage Power-Up ๐Ÿ”„:

    • Takes Continuous Delivery up a notch to full deployment.

    • No manual brakes, high automation mode.

  • Quick & Automatic Deployment ๐Ÿญ:

    • Changes go live almost instantly.

    • No waiting around; automation takes charge.

  • Cloud Journey for Apps โ˜๏ธ:

    • Code changes travel through the cloud.

    • Developer-driven, live in minutes with automated tests.

  • Push Button, Not Traffic Light ๐Ÿค–:

    • Fully automated release process.

    • Deploy to live production whenever needed.

  • Familiar Tools Still Here ๐Ÿš€:

    • AWS CodeDeploy, Jenkins, GitLab.

CI and CD Workflow

The below image describes how Continuous Integration combined with Continuous Delivery helps quicken the software delivery process with lower risks and improved quality.

CI and CD Workflow

CI / CD workflow

We have seen how Continuous Integration automates the process of building, testing, and packaging the source code as soon as it is committed to the code repository by the developers. Once the CI step is completed, the code is deployed to the staging environment where it undergoes further automated testing (like Acceptance testing, Regression testing, etc.). Finally, it is deployed to the production environment for the final release of the product.

If the deployment to production is a manual step. In that case, the process is called Continuous Delivery whereas if the deployment to the production environment is automated, it is referred to as Continuous Deployment.

Why is CI/CD Important?

CI/ CD enables organizations to develop software quickly and efficiently. CI/CD enables an effective process for getting products and software to market faster than ever before, continuously moving code into production, and ensuring a steady flow of new features

*Unpacking the Build Job ๐Ÿ—๏ธ**

A Jenkins build job contains the configuration for automating a specific task or step in the application building process. These tasks include gathering dependencies, compiling, archiving, or transforming code, and testing and deploying code in different environments.

Jenkins supports several types of build jobs, such as freestyle projects, pipelines, multi-configuration projects, folders, multibranch pipelines, and organization folders.

How to Set up a Build Job in Jenkins

Follow the steps outlined below to set up and run a new Jenkins freestyle project.

Step 1: Create a New Freestyle Project

1. Click the New Item link on the left-hand side of the Jenkins dashboard.

Click the New Item link on the left-hand side of the Jenkins dashboard

2. Enter the new project's name in the Enter an item name field and select the Freestyle project type. Click OK to continue.

Enter the project name, select the project type, and click OK to confirm

3. Under the General tab, add a project description in the Description field.

Add a Jenkins project description

Step 2: Add a Build Step

1. Scroll down to the Build section.

2. Open the Add build step drop-down menu and select Execute shell.

Select Execute Windows batch command from the Add build step drop-down menu

3. Enter the commands you want to execute in the Command field. For this tutorial, we are using a simple set of commands that display the current version of Java and Jenkins working directory:

java -version
dir

4. Click the Save button to save changes to the project.

Save changes to the project

Note: Need a cheap sandboxing environment with automated OS-deployment options? See how easy it is to deploy a development sandbox for as little as $0.10/hour.

Step 3: Build the Project

1. Click the Build Now link on the left-hand side of the new project page.

Use the Build Now link to build the a new project version

2. Click the link to the latest project build in the Build History section.

Click the link to open the latest build version

3. Click the Console Output link on the left-hand side to display the output for the commands you entered.

Click the link to open the build console output

4. The console output indicates that Jenkins is successfully executing the commands, displaying the current version of Java and Jenkins working directory.

Today's Tasks - Docker Automation with Jenkins ๐ŸŽฏ

Task-01: Dockerize Your App ๐Ÿณ

Certainly! A hands-on section can guide the reader through the actual steps of implementing Task-01 using Jenkins. Here's an example:

Hands-On: Configuring Jenkins for Automated Docker Builds and Deployment ๐Ÿคฒ๐Ÿ’ป

Step 1: Set Up a Jenkins Agent

  1. Open your Jenkins dashboard and navigate to "Manage Jenkins."

  2. Click on "Manage Nodes and Clouds."

  3. Create a new Node (agent) tailored to your Dockerized app's needs.

  4. Ensure Docker is installed on this agent. This agent will help Jenkins understand and execute Docker commands.

Step 2: Create a Freestyle Project

  1. Go back to the Jenkins dashboard.

  2. Click on "New Item" to create a new project.

  3. Choose "Freestyle project" and give it a meaningful name.

  4. In the project configuration, link it to your version control system if needed.

Step 3: Configure the Build Section

  1. In your project, find the "Configure" option.

  2. Scroll down to the "Build" section.

  3. Click on "Add build step" and choose "Execute shell" (for Linux/Mac) or "Execute Windows batch command" (for Windows).

Step 4: Add "docker build" Build Step

  1. In the command box, type the following to build your Docker image:

     docker build -t your-image-name:tag -f path/to/Dockerfile .
    

    Replace your-image-name:tag with your desired image name and tag. Replace path/to/Dockerfile with the actual path to your Dockerfile.

Step 5: Add "docker run" Build Step

  1. Add another build step.

  2. In the command box, type the following to run your Docker container:

     docker run -p 8080:80 your-image-name:tag
    

    Replace your-image-name:tag with the image name and tag you used in the previous step.

Step 6: Save and Build

  1. Save your project configuration.

  2. Trigger a manual build to see Jenkins in action.

  3. Check the console output for any issues or successful execution.

Congratulations! You've just configured Jenkins to automate the build and run steps for your Dockerized app. ๐ŸŽ‰๐Ÿ’ป

Certainly! Let's break down the hands-on steps for your Jenkins project to run Docker Compose commands:

Hands-On: Jenkins and Docker Compose Automation ๐Ÿค–๐Ÿณ

Task-02: Docker Compose Automation

  1. Prepare Your Jenkins:

    • Ensure Jenkins is up and running.

    • Verify that the necessary plugins (Docker and Docker Compose) are installed.

  2. Create a New Jenkins Project:

    • In Jenkins, create a new project specifically for running Docker Compose commands.

    • Choose the "Freestyle Project" option.

  3. Configure the Project:

    • Name your project something descriptive, like "Docker Compose Automation."

    • Set up the version control settings if applicable.

  4. Build Section Configuration:

    • In the project configuration, head to the "Build" section.

    • Add a build step to run the "docker-compose up -d" command.

    • Specify the path to your Docker Compose file (Hint: Use the one from Day-19).

  5. Cleanup Step Configuration:

    • Add another build step for cleanup.

    • Run the "docker-compose down" command to stop and remove containers.

  6. Save and Trigger Automation:

    • Save your project configuration.

    • Manually trigger the project or set up automatic triggers based on your preferences.

  7. Observe Jenkins in Action:

    • Watch as Jenkins fetches your Docker Compose file, starts the containers, and performs cleanup when needed.
  8. Check Console Output:

    • After running the project, check the console output in Jenkins.

    • Ensure that Docker Compose commands are executed successfully.

By following these hands-on steps, you're automating the deployment and cleanup of multiple containers using Docker Compose through Jenkins.

Conclusion

In today's #90daysofdevops challenge, DevOps engineers mastered Jenkins Freestyle Projects, showcasing expertise in Continuous Integration (CI), Continuous Delivery (CD), and Jenkins build jobs. They harnessed the versatility of Jenkins build jobs as automation blueprints and flexed their skills in crafting Freestyle Projects. Practical tasks, including Dockerized app orchestration and Docker Compose for multi-container deployments, demonstrated Jenkins' real-world application. This achievement propels the community towards greater DevOps excellence, combining innovation, automation, and transformation in a dynamic and collaborative landscape. ๐Ÿ”ง๐Ÿ’ป๐ŸŒ

ย