Getting Started with Jenkins  #Day-22

Getting Started with Jenkins #Day-22

How to Start with Jenkins Today

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.

  • Jenkins is a tool that is used for automation, and it is an open-source server that 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.

  • Jenkins achieves Continuous Integration with the help of plugins. Plugins allow the integration of Various DevOps stages. If you want to integrate a particular tool, you need to install the plugins for that tool. For example Git, Maven 2 project, Amazon EC2, HTML publisher etc.

Let us do discuss the necessity of this tool before going ahead to the procedural part for installation:

  • Nowadays, humans are becoming lazy day by day so even having digital screens and just one click button in front of us then also need some automation.

  • Here, I’m referring to that part of automation where we need not have to look upon a process(here called a job) for completion and after it doing another job. For that, we have Jenkins with us.

Task 1: What is Jenkins and Why is it Used?

Jenkins is an open-source automation server used to streamline various aspects of software development. It plays a pivotal role in continuous integration and continuous delivery (CI/CD), allowing developers to automate the repetitive tasks involved in building, testing, and deploying code. Jenkins was originally developed as the Hudson project but was renamed Jenkins in 2011 after a fork in the community.

Integration in the DevOps Lifecycle:

In the DevOps lifecycle, Jenkins is a crucial tool for ensuring smooth, continuous integration and delivery. It integrates with various version control systems like Git, SVN, and Mercurial, among others. By doing so, it continuously monitors repositories for changes and triggers build processes automatically whenever new code is pushed. This automation significantly reduces the risk of human error and accelerates the delivery process.

Benefits of Using Jenkins:

  1. Automation: Jenkins automates the build, test, and deployment processes, allowing developers to focus on coding rather than repetitive tasks.

  2. Continuous Integration: It ensures that code changes are integrated frequently, which helps in identifying bugs early in the development cycle.

  3. Extensibility: Jenkins has a vast ecosystem of plugins that enhance its capabilities, integrating with a wide range of tools and services used in software development.

  4. Scalability: Jenkins can distribute build and test loads across multiple machines, making it suitable for projects of any size.

  5. Flexibility: It supports various configurations and setups, allowing teams to customize pipelines according to their specific needs.

Automating Build, Test, and Deployment:

Jenkins automates the build process by compiling code, running tests, and packaging the application. It can also deploy the application to different environments, such as development, staging, or production, based on predefined rules. This automation ensures consistency and reliability, as the same steps are followed every time a deployment is made.

In summary, Jenkins is an essential tool for modern software development, enabling teams to implement CI/CD practices effectively. Its ability to automate and integrate with numerous tools and services makes it a cornerstone in the DevOps lifecycle.

Task 2: Create a Freestyle Pipeline to Print "Hello World"

Step-by-Step Guide to Create a Freestyle Pipeline in Jenkins:

  1. Install Jenkins:

    • Ensure Jenkins is installed and running on your server or local machine.
  2. Create a New Freestyle Project:

    • Go to the Jenkins dashboard.

    • Click on "New Item" to create a new job.

    • Enter a name for your job (e.g., "Hello World Pipeline") and select "Freestyle project." Click "OK."

  3. Configure the Pipeline:

    • In the configuration page of the new job, navigate to the "Build" section.
  4. Add Build Steps:

    • Print "Hello World":

      • Click on "Add build step" and select "Execute shell" (or "Execute Windows batch command" for Windows).

      • Enter the following command:

          echo "Hello World"
        
    • Print the Current Date and Time:

      • Click "Add build step" again and select "Execute shell."

      • Enter the following command:

          date
        
    • Clone a GitHub Repository and List Its Contents:

      • Click "Add build step" again and select "Execute shell."

      • Enter the following commands:

          git clone https://github.com/your-repository-url.git
          ls your-repository-name
        
      • Replace https://github.com/your-repository-url.git with the actual URL of your GitHub repository and your-repository-name with the name of the repository.

  5. Configure Periodic Build:

    • Scroll to the "Build Triggers" section.

    • Check the "Build periodically" option.

    • Enter the cron syntax for running the job every hour:

        H * * * *
      
    • This will schedule the job to run every hour at a random minute to avoid load spikes.

  6. Save the Configuration:

    • Click "Save" to apply the configuration.
  7. Run the Pipeline:

    • Manually trigger the job once to test it by clicking on "Build Now."

    • Check the console output to ensure that the steps are executed correctly.

By following these steps, you will have created a Jenkins Freestyle project that prints "Hello World," displays the current date and time, clones a GitHub repository, lists its contents, and runs periodically every hour. This pipeline demonstrates Jenkins' capabilities in automating tasks and integrating with version control systems.

Conclusion

Jenkins is an indispensable tool in the modern software development landscape, facilitating seamless continuous integration and continuous delivery (CI/CD) processes. Its ability to automate repetitive tasks, integrate with a wide array of tools, and provide scalability and flexibility makes it a cornerstone in the DevOps lifecycle. By following the steps outlined in this guide, you can harness the power of Jenkins to streamline your development workflows, ensuring consistent and reliable software delivery. Whether you're a seasoned developer or new to DevOps, Jenkins offers the tools and capabilities to enhance your productivity and efficiency.

Connect and Follow:

LinkedIn | Twitter | GitHub

Like👍 | Share📲 | Comment💭