Getting Started with Jenkins

Getting Started with Jenkins

·

7 min read

What is Jenkins⁉️

  • Jenkins is a Java-based open source continuous integration-continuous delivery and deployment (CI/CD) automation software DevOps tool. It is used to implement pipelines, which are CI/CD workflows.

  • Jenkins uses plugins to achieve Continuous Integration. Plugins enable the integration of different DevOps stages. If you want to integrate a specific tool, you must first install its plugins. For instance, Git, Maven 2 projects, Amazon EC2, HTML publishers, and so on.

  • Jenkins is an automation tool that is an open-source server that allows all developers to build, test, and deploy software. Because it is written in java, it works or runs on java. We can use Jenkins to perform continuous integration of projects (jobs) or end-to-end automation.

How and where it is used ❓🤔

  • The strength of Jenkins lies in its ability to automate and orchestrate various stages of the software development lifecycle. In this chapter, we'll look at how Jenkins is used to streamline development processes in real-world scenario.

  • CI (Continuous Integration):

    • Continuous Integration entails integrating code changes from multiple developers into a shared repository regularly. Jenkins is critical in automating this process:

    • Jenkins can monitor version control systems (for example, Git) for new commits. Jenkins pulls the most recent code when changes are detected.

    • Jenkins can initiate the build process, which includes compiling the code and generating executable artefacts.

    • Jenkins can run unit tests to ensure that code changes have not introduced new bugs or regressions.

    • Jenkins generates comprehensive reports on build status, test results, and code coverage. If any tests fail, developers are notified immediately.

  • Continuous Delivery (CD):

    • Continuous Delivery extends the CI process by automating the deployment of tested code to various environments, ensuring that it's ready for release.

    • Staging and QA: Jenkins can deploy the built artefacts to staging or QA environments, allowing testing in an environment that closely resembles production.

    • Integration Testing: Automated integration tests can be run to verify that different components of the software work harmoniously.

    • User Acceptance Testing (UAT): Jenkins can facilitate UAT by deploying to a UAT environment, where stakeholders can validate the software.

    • Production Deployment: Once the software passes all tests and approvals, Jenkins can automate the deployment to production, minimizing manual intervention and potential errors.

  • Automation Pipelines:

    • One of Jenkins' key features is the ability to define pipelines as code, which offers several benefits.

    • Reproducibility: Pipeline code stored in version control ensures that pipeline configurations are consistent across environments.

    • Versioning: Changes to the pipeline can be tracked, enabling easy collaboration and rollbacks if needed.

    • Scalability: Jenkins pipelines can be designed to run on multiple agents simultaneously, distributing workload and reducing build times.

  • Scheduled Jobs and Triggered Builds:

    • Jenkins can be configured to perform tasks on a schedule or in response to events:

      • Nightly Builds: Regular nightly builds can be scheduled to ensure that code changes from different developers are integrated daily.

      • Triggered Builds: Jenkins can be set to build and test whenever a specific event occurs, like a new commit, a pull request, or a code merge.

  • Notifications and Reporting:

    • Jenkins keeps development teams informed about the status of builds and deployments.

    • Email Notifications: Developers receive email notifications about build results, test failures, and other critical events.

    • Integration with Chat Tools: Jenkins can be integrated with messaging platforms like Slack, providing real-time updates to development teams.

  • Plugin Integration:

    • Jenkins' plugin ecosystem enhances its functionality:

    • Version Control Integration: Plugins enable seamless integration with version control systems, fetching code updates and triggering builds.

    • Cloud Services: Jenkins can use plugins to interact with cloud services like AWS, Azure, and Google Cloud, facilitating deployment and infrastructure management.

Benefits of using Jenkins📈

1. Automation: Making Things Easier and Error-Free

Imagine having a robot assistant that can take care of repetitive tasks for you. Jenkins is like that for developers. It does the repetitive and boring tasks automatically, which means fewer chances of mistakes and faster work.

2. Continuous Integration (CI): Catching Mistakes Early

Picture this: you're building a puzzle, and you check every piece as you add it to make sure it fits perfectly. That's what Jenkins does with code. It checks the pieces of code as they're added, finding any problems before they become big issues. This helps fix things faster and keeps the project moving smoothly.

3. Continuous Delivery (CD): Smooth Delivery of Ready Stuff

Think of Jenkins as a super-efficient delivery service for software. Once the code is checked and ready, Jenkins makes sure it's delivered to where it's supposed to go—like a staging area for testing or directly to the real users. This saves time and effort and ensures that only reliable code reaches the users.

4. Extensibility: Tailoring to Your Needs

Imagine a toolbox with tons of tools that you can pick and choose from to create your perfect toolkit. Jenkins is a bit like that. It comes with a bunch of tools (called plugins) that you can use to add new features or customize things to fit your project's unique needs.

5. Scalability: Growing Without Problems

Think of your project like a garden. As it grows, you need more space and resources to keep it healthy. Jenkins can handle small gardens and huge ones too. It can spread its work across multiple computers, so your project can keep growing without slowing down.

In simple terms, Jenkins is like a reliable helper that automates tasks, catches problems early, delivers code smoothly, can be customized to your liking, and grows with your project. It's like having a superhero sidekick for your software development journey!

How to install 🤯⁉️

Step 1: Checking Java Before you start, you need to make sure your computer has Java installed. Think of Java as the engine that powers Jenkins.

  1. Open your terminal: This is like a text-based control center for your computer.

  2. Type in: java -version

  3. Press Enter.

If you see a version number (like "Java 11" or similar), you're good to go. If you don't see anything or it says Java is not found, you need to install Java before proceeding.

# Install java
sudo apt-get install openjdk-17-jdk

Step 2: Installing Jenkins

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
  • Run the above code in your terminal and jenkins will be install in your system

Step 3 Checking Status :

  • To check the status you can run service jenkins status

  • If it's not running you can run systemctl start jenkins and to start jenkins automatically run systemctl enable jenkins

Step 4: Accessing Jenkins

  1. Open your web browser (like Chrome, Firefox, or Edge).

  2. In the address bar at the top, type: http://localhost:8080 and press Enter.

    Here i have typed and IP:port

  3. A page will appear asking for a password. To find the password, go back to the terminal and type: sudo cat /var/lib/jenkins/secrets/initialAdminPassword

  4. Copy the password from the terminal and paste it into the password field on the browser page.

  5. Follow the on-screen instructions to finish setting up Jenkins, creating an admin user, and installing suggested plugins .

  6. Follow the instructions and create first admin user

  7. After finishing all the steps , you will see this window

Hands-On 💻

  • Let's create a freestyle pipeline to print "Hello World!!" or any message you want .

  • After logging in to jenkins dashboard , click on New Item to create a new job.

  • Now , it will ask you to enter item name and choose the type of project , wrtie your item name and select freestyle project and click on OK .

  • After this , it will ask you for a description , you can give any simple description for this .

  • Now scroll down till u find Build steps , click on it and select Execute Shell and enter the command you want to execute and save .

  • Now click on Build Now to build the project .

  • When the build is finished, click on the build number on the left hand side to see the console output. The output of the "echo" command will be displayed.

I hope now you can create your own freestyle projects on Jenkins..!

Happy Learning :D