๐Ÿš€๐Ÿ“… Day 23 DevOps Challenge - Jenkins Freestyle Project for DevOps Beginners ๐Ÿ› ๏ธ๐Ÿš€

๐Ÿš€๐Ÿ“… Day 23 DevOps Challenge - Jenkins Freestyle Project for DevOps Beginners ๐Ÿ› ๏ธ๐Ÿš€

ยท

5 min read

Introduction

In the exciting world of DevOps, where the magic happens in software development, we're going to explore a superhero tool called Jenkins! ๐Ÿฆธโ€โ™‚๏ธ Imagine Jenkins as your personal helper that automates tasks and makes your life easier. Let's dive into the Jenkins Freestyle Projects and see how they fit into the puzzle of CI/CD for beginners like you!

CI/CD: The DevOps Super Duo ๐Ÿค–๐Ÿš€

Picture CI (Continuous Integration) as your trusty sidekick that brings all the superheroes (developers) together to work on a single mission: building awesome software. It makes sure that everyone's code plays nicely together and catches bugs early to save the day ๐Ÿž๐Ÿฆ . CD (Continuous Delivery) swoops in after CI and ensures that your software is ready to fly into the world without any hiccups ๐Ÿš€.

Meet the Build Jobs ๐Ÿ—๏ธ

Think of build jobs as the different steps in a secret recipe to create a magical potion (your software). These steps include mixing ingredients, stirring, and finally pouring out a perfect potion. In Jenkins, we have different types of build jobs. Today, we're focusing on the "Freestyle Projects," which is like your canvas for creating your magical spells!

Freestyle Projects: Your DevOps Playground ๐ŸŽฎ๐Ÿ”ง

  1. Build and Compile ๐Ÿ› ๏ธ: Imagine this as creating a blueprint for your software. Jenkins takes your code and turns it into something the computer can understand and run. No more gibberish!

  2. Testing Magic ๐Ÿงชโœจ: Here, Jenkins becomes a skilled magician. It runs tests to make sure your software works as expected. Like a spell checker for your code!

  3. Saving Artifacts ๐Ÿ“ฆ๐Ÿ”ฎ: Artifacts are like treasures Jenkins helps you collect after the spell is cast. These could be your software, special documents, or even a recipe to recreate the potion!

  4. Custom Adventures ๐Ÿ“œ๐Ÿ”: With freestyle projects, you're the boss! You can add your own instructions, like a wizard adding personal touches to a spell. Got a unique task? Jenkins can handle it!

  5. Deploying with Confidence ๐Ÿšš๐ŸŒŽ: Think of deployment as sending your magical potion into the real world. Jenkins helps you do this safely, making sure your potion works its charm everywhere.

Time to Embrace Your DevOps Powers! ๐Ÿฆนโ€โ™€๏ธ๐Ÿš€

Jenkins Freestyle Projects are like the training wheels for your DevOps journey. They empower you to automate tasks, catch bugs, and sprinkle your magic across the software world. With CI and CD as your dynamic duo and Jenkins as your trusty sidekick, you're ready to conquer the world of DevOps, one spell (or code) at a time! ๐ŸŒŸ๐Ÿ”ฅ

Task-01: Jenkins Freestyle Project for Building and Deploying Your App

Hello there, DevOps Explorer! Ready to take your app to the next level with Jenkins? Let's dive into a simple yet enchanting task where you'll create a Jenkins freestyle project to build and deploy your app using Docker.

Step 1: Prepare Your Magic Workshop

  1. Log into Jenkins ๐ŸŒ: Access your Jenkins dashboard โ€“ your hub for all things magical.

  2. Create a New Freestyle Project ๐Ÿ—๏ธ: Click "New Item," give your project a name, and select "Freestyle project."

Step 2: Configure the build steps:

  • In the Source Code Management section, use the GitHub Repository URL to access the Dockerfile

Step 3: Casting the Build and Deploy Spell

  1. Configure Build Step ๐Ÿ”ง: In your project's configuration, scroll down to the "Build" section.

  2. Add a Build Step โž•: Click "Add build step" and choose "Execute shell" or "Execute Windows batch command," depending on your system.

  3. Build the Container ๐Ÿ—๏ธ: Inside the shell command box, enter:

     cd /var/lib/jenkins/workspace/item-name
     docker build -t notes-app .
     echo "Image created"
    

    This command crafts your app's container image.

  4. Add Another Build Step โž•: Click again and choose the same command type.

  5. Summon the Container ๐Ÿงžโ€โ™‚๏ธ: In the command box, enter:

     echo "Docker images"
     docker images
     echo "------------------------------------"
     docker run -d -p 8000:8000 notes-app:latest
     echo "Container is created and running"
    

  6. This command starts your app's container, making it accessible at port 8000.

Step 4: Unleash the Magic

  1. Save Your Spell ๐Ÿ’พ: Hit "Save" to seal your freestyle project's enchantment.

  2. Cast Your Spell ๐Ÿช„: Click "Build Now" to invoke your project's magic. Watch as Jenkins weaves its automation to build and deploy your app.

  3. Witness the Enchantment โœจ: Check the console output โ€“ a magical scroll revealing the progress of your spell casting.

Conclusion: Your App, Up and Running with Jenkins!

Congratulations, you've just summoned the power of Jenkins to build and deploy your app effortlessly! With this simple freestyle project, you've taken a big step into the world of DevOps magic. Keep exploring Jenkins, and tweaking your spells, and your app will continue to thrive and amaze. The journey has just begun! ๐Ÿš€๐Ÿ”ฎ

Task-02: Managing Docker Compose with Jenkins ๐Ÿณ๐Ÿš€

Step 1: Create a New Jenkins Project

  1. Log in to your Jenkins dashboard.

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

  3. Enter a name for your project, choose "Freestyle project," and click "OK."

Step 2: Configure Jenkins Project

  1. On the project configuration page:

    • Under "General," you can provide a project description.

    • Under "Source Code Management," select the appropriate option if you're using version control.

    • Under "Build Triggers," you can choose when to trigger the build (e.g., after a push to your repository).

Step 3: Configure Build Steps

  1. In the "Build" section, click "Add build step" and choose "Execute shell."

  2. In the shell command box, enter the following command to start the containers using Docker Compose:

     cd /path/to/your/docker-compose/folder
     docker-compose up -d
    
  3. Add another build step for the cleanup process:

     cd /path/to/your/docker-compose/folder
     docker-compose down
    

Step 4: Save and Run the Jenkins Project

  1. Click "Save" to save your Jenkins project configuration.

  2. You can manually run the project by clicking "Build Now" or wait for the configured triggers to initiate the build.

Step 5: Verify the Build Steps

When the Jenkins project runs, it will execute the specified commands. It will start the containers using the docker-compose up -d command and then stop and remove them using the docker-compose down command.

Please replace /path/to/your/docker-compose/folder with the actual path to the directory containing your docker-compose.yml file.

Remember to ensure that Jenkins has the necessary permissions to execute Docker commands and access the Docker Compose file. Additionally, make sure Docker and Docker Compose are properly installed on the Jenkins server.

Always exercise caution when using automated build and cleanup processes, especially in production environments. Test thoroughly in a controlled environment before applying to critical systems.

Did you find this article valuable?

Support Adarsh Jha by becoming a sponsor. Any amount is appreciated!

ย