Day 23: Jenkins Freestyle Project for DevOps Engineers

Day 23: Jenkins Freestyle Project for DevOps Engineers

ยท

3 min read

Continuous Integration and Continuous Deployment (CI/CD) are fundamental practices in modern software development. In this detailed tutorial, we'll break down the basics of CI/CD, understand the concept of a build job, and dive into creating Jenkins Freestyle Projects to automate Docker tasks. Whether you're a beginner or an experienced developer, this guide aims to make the process accessible to all.

Understanding CI/CD ๐Ÿ”„

CI/CD involves automating the process of integrating code changes and deploying applications. This ensures that your code is consistently tested and delivered, promoting a more efficient and reliable development workflow.

What is a Build Job? ๐Ÿ—๏ธ

In Jenkins, a build job is a task that takes your source code, compiles it, runs tests, and produces artifacts. These jobs are a crucial part of CI/CD pipelines, guaranteeing that your application is in a deployable state.

Exploring Freestyle Projects ๐ŸŽจ

Jenkins Freestyle Projects are user-friendly and flexible, making them an excellent starting point for CI/CD beginners. These projects allow you to configure build jobs without needing extensive scripting.

For the tasks that follow, I have used the below projects:

  1. Dockerizing a Django To-Do App on AWS

  2. Deploying a Two-Tier Flask App with Docker-Compose

Task-01: Building and Running Docker Containers ๐Ÿณ

Step 1: Create an Agent for Your App ๐Ÿ•ต๏ธโ€โ™‚๏ธ

  1. In Jenkins, go to "Manage Jenkins" > "Manage Nodes and Clouds."

  2. Click "New Node" to create a new agent. Give it a name, choose "Permanent Agent," and configure the necessary settings.

Step 2: Configure a Freestyle Project โš™๏ธ

  1. Click on "New Item" on the Jenkins dashboard.

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

  3. Under the "General" section, check "Restrict where this project can be run" and select your created agent.

Step 3: Add Build Steps ๐Ÿ› ๏ธ

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

  2. Click on "Add build step" and choose "Execute shell" (for Unix-based systems) or "Execute Windows batch command" (for Windows).

  3. For the "Command," enter docker build -t your-app-image . to build your Docker image.

  4. Add a second build step by clicking "Add build step" again. Choose "Execute shell" or "Execute Windows batch command," and enter docker run -d -p 8001:8001 your-app-image to run your Docker container.

Step 4: Save and Build ๐Ÿ’พ

  1. Save your project configuration.

  2. Trigger a build by clicking "Build Now" on the project dashboard.

Jenkins will now execute the specified build steps, creating a Docker image and running a container for your app.

Step 5: Manual Browser Testing ๐ŸŒ

  1. Open your preferred web browser.

  2. Navigate to http://localhost:8080 to access your Todo App manually.

Task-02: Docker Compose Automation ๐Ÿค–

Step 1: Create a Jenkins Project ๐Ÿ—๏ธ

  1. Create a new Freestyle Project following the steps above.

Step 2: Configure Build Steps โš™๏ธ

  1. Under the "Build" section, click "Add build step" and choose "Execute shell" or "Execute Windows batch command."

  2. Enter the command docker-compose -f path/to/your/docker-compose-file.yml up -d to start multiple containers defined in your Docker Compose file.

  3. Add a cleanup step by clicking "Add build step" again. Choose "Execute shell" or "Execute Windows batch command," and enter docker-compose -f path/to/your/docker-compose-file.yml down to stop and remove containers.

Step 3: Save and Run ๐Ÿ’พ

  1. Save your project configuration.

  2. Trigger a build to see Jenkins automating the deployment of your Docker Compose application.

Step 4: Manual Browser Testing for Two-Tier Flask App ๐ŸŒ

  1. Open your preferred web browser.

  2. Navigate to http://localhost:5000 to access your Two-Tier Flask App manually.

With these detailed steps, even beginners can successfully set up Jenkins Freestyle Projects for Docker automation. Remember, practice is key, so feel free to experiment with different configurations to enhance your CI/CD skills. Happy coding! ๐Ÿš€

Let's connect on LinkedIn

ย