๐๐ Day 23 DevOps Challenge - Jenkins Freestyle Project for DevOps Beginners ๐ ๏ธ๐
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 ๐ฎ๐ง
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!
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!
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!
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!
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
Log into Jenkins ๐: Access your Jenkins dashboard โ your hub for all things magical.
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
Configure Build Step ๐ง: In your project's configuration, scroll down to the "Build" section.
Add a Build Step โ: Click "Add build step" and choose "Execute shell" or "Execute Windows batch command," depending on your system.
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.
Add Another Build Step โ: Click again and choose the same command type.
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"
This command starts your app's container, making it accessible at port 8000.
Step 4: Unleash the Magic
Save Your Spell ๐พ: Hit "Save" to seal your freestyle project's enchantment.
Cast Your Spell ๐ช: Click "Build Now" to invoke your project's magic. Watch as Jenkins weaves its automation to build and deploy your app.
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
Log in to your Jenkins dashboard.
Click on "New Item" to create a new project.
Enter a name for your project, choose "Freestyle project," and click "OK."
Step 2: Configure Jenkins Project
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
In the "Build" section, click "Add build step" and choose "Execute shell."
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
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
Click "Save" to save your Jenkins project configuration.
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.