Getting Started with Jenkins: From Installation to Your First Freestyle Pipeline – Saying Hello to the World of Automation🚀
Tired of manual repetitive tasks in your software workflow? Meet Jenkins – an open-source automation server that revolutionizes your development process. Say goodbye to manual builds, tests, and deployments! In this guide, discover Jenkins basics, its perks, and an installation walkthrough with code snippets. Let's dive in and simplify your developer life! 🚀
🔶What is Jenkins?
Jenkins is an open-source continuous integration-continuous delivery and deployment (CI/CD) automation software DevOps tool written in the Java programming language. It is used to implement CI/CD workflows, called pipelines.
It allows all the developers to build, test and deploy software. It works or runs on Java as it is written in Java. By using Jenkins we can make a continuous integration of projects(jobs) or end-to-endpoint automation.
🔶What is CI/CD?
CI/CD stands for Continuous Integration and Continuous Delivery (or Continuous Deployment), which are essential practices in modern software development. They focus on automating and optimizing the process of building, testing, and delivering software to users.
Here's what each term means:
Continuous Integration (CI):
CI involves regularly integrating code changes from multiple developers into a shared repository.
Developers commit their code changes frequently, and these changes are automatically integrated and built together.
Automated tests are run to ensure that new code changes don't break existing functionality.
Continuous Delivery (CD):
CD takes CI a step further by automating the deployment of code changes to production-like environments.
Once code changes pass the automated tests in the CI phase, they are automatically prepared for deployment.
The code is deployed to staging or production-like environments, allowing for more thorough testing before actual deployment.
CD ensures that software is always in a deployable state, ready to be released at any time.
Continuous Deployment:
This is an extension of continuous delivery where code changes are not only automatically prepared for deployment but also automatically deployed to production environments.
Every successful code change in the CI/CD pipeline results in an automatic deployment to production.
Continuous Deployment aims to minimize the time between writing code and making it available to users.
🔶Benefits of Using Jenkins
Automation: Jenkins allows you to automate repetitive tasks, reducing manual intervention and human errors.
Continuous Integration and Continuous Deployment (CI/CD): Jenkins is a key tool for implementing CI/CD pipelines, helping you deliver high-quality software faster.
Extensibility: With a vast array of plugins, Jenkins can be tailored to your specific needs and integrated with other tools in your tech stack.
Flexibility: Jenkins supports a wide range of programming languages and tools, making it suitable for various types of projects.
Monitoring and Reporting: Jenkins provides detailed insights into your build and deployment processes, aiding in identifying issues and optimizing workflows.
🔶Installation Guide
Prerequisites: Before you begin, ensure that you have the following prerequisites:
A Linux-based system (Ubuntu, CentOS, Debian, etc.).
Java Development Kit (JDK) installed. Jenkins requires Java to run.
Follow these steps to install Jenkins on your system:
🛠️Installing Jenkins on Linux
Step 1: Update Package Repositories: Open a terminal window and run the following commands to update your package repositories:
#For Ubuntu/Debian:
sudo apt update
#For CentOS:
sudo yum update
Step 2: Install Java: Jenkins relies on Java, so you'll need to install it. Run the following command to install OpenJDK (recommended):
#For Ubuntu/Debian:
sudo apt install openjdk-11-jdk
#For CentOS:
sudo yum install java-11-openjdk-devel
Step 3: Add Jenkins Repository: To install the latest version of Jenkins, you can add its official repository. Run the following commands:
#For Ubuntu/Debian:
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
#For CentOS:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Step 4: Install Jenkins: Once the repository is added, update your package cache and install Jenkins:
#For Ubuntu/Debian:
sudo apt update
sudo apt install jenkins
#For CentOS:
sudo yum install jenkins
Step 5: Start and Enable Jenkins: After the installation, start the Jenkins service and enable it to start on boot:
#For Ubuntu/Debian:
sudo systemctl start jenkins
sudo systemctl enable jenkins
#For CentOS:
sudo systemctl start jenkins
sudo systemctl enable jenkins
Step 6: Access Jenkins Web Interface: Jenkins runs on port 8080 by default. Open your web browser and navigate to http://your_server_ip_or_domain:8080
. You'll be prompted to unlock Jenkins by providing an initial admin password.
Step 7: Unlock Jenkins and Install Plugins: Retrieve the initial admin password from the server using the following command:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy the password and paste it into the Jenkins setup wizard in your browser. Follow the prompts to install recommended plugins or select specific ones.
Step 8: Create Admin User: Set up an admin username and password for Jenkins.
Step 9: Start Using Jenkins: Confirm the Jenkins URL configuration and click "Save and Finish." You're now ready to start using Jenkins!
🛠️Installing Jenkins on Windows
Step 1: Download and Install Java: Download and install the Java Development Kit (JDK) from the official Oracle website.
Step 2: Download Jenkins Installer: Download the Jenkins Windows installer from the official Jenkins website (select the Windows installer option).
Step 3: Run Jenkins Installer: Run the downloaded installer and follow the on-screen instructions. Choose the installation directory and other preferences.
Step 4: Access Jenkins Web Interface: Once the installation is complete, Jenkins will be accessible at http://localhost:8080
in your web browser.
Step 5: Unlock Jenkins and Install Plugins: Retrieve the initial admin password from the installation directory (usually C:\Program Files\Jenkins\secrets\initialAdminPassword
). Follow the setup wizard to install recommended plugins or select specific ones.
Step 6: Create Admin User: Set up an admin username and password for Jenkins.
Step 7: Start Using Jenkins: Confirm the Jenkins URL configuration and click "Save and Finish." You're now ready to start using Jenkins!
Congratulations! You've successfully installed Jenkins on both Linux and Windows systems. Whether you're a Linux enthusiast or a Windows user, you can now leverage Jenkins to automate and streamline your software development processes.
🔶Create a freestyle pipeline to print "Hello World!!
Certainly! In Jenkins, you can create a Freestyle project to achieve this. Here's how you can create a simple Freestyle pipeline that prints "Hello World!!" when executed:
Create a New Freestyle Project:
Log in to your Jenkins instance.
Click on "New Item" to create a new project.
Enter a name for your project, e.g., "HelloWorldPipeline".
Select "Freestyle project" and click "OK".
Configure the Pipeline:
You'll be redirected to the configuration page for your project. Here's what you need to set up:
Source Code Management (Optional): If you're working with source code, you can configure your repository details here. For this example, we'll skip this step.
Build:
Click on "Add build step" and select "Execute shell".
In the "Command" text area, enter the command to print "Hello World!!":
echo "Hello World!!"
Post-build Actions: These are actions that will be performed after the build completes. For our example, we won't need any post-build actions.
Save and Run:
Click "Save" to save the configuration.
You'll be redirected to the project's main page.
Click on "Build Now" to start the pipeline execution.
Once the build completes, you'll see the console output showing "Hello World!!".
🔶Wrapping Up
Jenkins is a powerful tool that can significantly improve your development workflow by automating tasks and streamlining processes. By following this installation guide, you've taken the first step toward harnessing the power of Jenkins. With its extensive plugin support and user-friendly interface, you'll be well on your way to creating efficient CI/CD pipelines and reaping the benefits of automation in your software projects. Happy coding! 🎉🤖