Jenkins

Jenkins

What is Jenkins!!!

Jenkins is a powerful open-source automation server that is widely used to automate the building, testing, and deployment of software. It is written in Java and runs on a wide variety of platforms, including Windows, Linux, and macOS. In this blog post, we will take a look at some examples of how Jenkins can be used to automate different parts of the software development process.

One common use case for Jenkins is to automate the building of software. This can be done by configuring a Jenkins job to run a build script or to execute a build tool, such as Maven or Gradle. For example, let's say you have a Java project stored in a Git repository. You can configure a Jenkins job to pull the latest code from the repository, compile the code using Maven, and then create a JAR or WAR file. This can save developers time and ensure that the build process is consistent and repeatable.

Jenkins also supports integration with other tools such as Selenium and Appium to automate the functional and end-to-end testing of web and mobile applications. Jenkins can also be integrated with test management tools like TestNG, JUnit and TestLink to manage the test cases, test execution and test results.

Jenkins also provides a rich set of reporting and analytics features, which allow you to monitor the performance of your build process and identify any issues that need to be addressed. This includes real-time status updates, build history, and detailed logs, which can be used to troubleshoot problems and optimize the performance of your build process.

Types of Jenkins Pipeline:-

1. Declarative Pipeline:-

The declarative syntax is a new feature that uses code for the pipeline. It provides a limited pre-defined structure. They are quite easy to write and understand. Thereby, it offers an easy & simple continuous delivery pipeline. The “pipeline” block is the main block that contains the entire declaration of a pipeline. For example:

pipeline {
    agent any
    stages {
        stage('Stage 1') {
            steps {
                echo 'Hello Stage 1'
            }
        }
        stage('Stage 2') {
            steps {
                echo 'Hello Stage 2'
            }
        }
    }
}

2. Scripted Pipeline:-

Unlike declarative syntax, the scripted pipeline syntax is the old traditional way to write the Jenkinsfile. This allows for more flexibility and control over the pipeline, but it can also make the pipeline more complex and harder to read. Moreover, it strictly follows the groovy syntax and helps to develop a complex pipeline as code. For example:

node {
    stage('Build') {
        echo 'Building...'
        sh 'make build'
    }
    stage('Test') {
        echo 'Testing...'
        sh 'make test'
    }
    stage('Deploy') {
        echo 'Deploying...'
        sh 'make deploy'
    }
}

Key concepts of Jenkins file:-

  • Pipeline- A pipeline is a set of instructions that includes continuous delivery processes. For example, creating an application, testing it, and deploying the same. Moreover, it is a critical element in declarative pipeline syntax, a collection of all stages in a Jenkins file. We declare different stages and steps in this block.

  • Node- A node is a key element in scripted pipeline syntax. Moreover, it acts as a machine in Jenkins that executes the Pipeline.

  • Stage- A stage consists of a set of processes that the Pipeline executes. Additionally, the tasks are divided in each stage, implying that there can be multiple stages within a Pipeline.

  • Steps- A step in Jenkins defines what we have to do at a particular step in the process. There can be a series of steps within the stage. Moreover, whatever step we define in a stage would be executed within it.

  • Agent- An agent is a directive that enables the users to execute multiple projects within the same Jenkins instance by distributing the load. Moreover, we assign an executor to the build through an agent. You can either use a single agent for the entire pipeline or use a distinct agent for the different stages of the pipeline. Subsequently, some of the parameters used with agents are-

    • Any: Any of the available agents execute the pipeline.

    • None: It is used at the pipeline root and implies no global agent, but each stage must specify its own agent.

    • Label- The labeled agent is used to execute the pipeline or the specific stage.

    • Docker: One can use the Docker images as the execution environment & specifying the agent as docker.

Advantages of using Jenkins:

  • Open-source and free: Jenkins is an open-source tool, which means that it can be freely downloaded and used without any licensing costs.

  • Easy to install and configure: Jenkins is easy to install and set up, and it can be configured to work with a wide variety of tools and technologies.

  • Large plugin ecosystem: Jenkins has a large and active community of developers who have created a wide variety of plugins to extend the functionality of the tool. This makes it easy to integrate Jenkins with other tools and technologies.

  • Distributed builds: Jenkins supports distributed builds, which allows you to distribute the build process across multiple machines. This can significantly improve the speed of the build process.

  • Support for multiple build triggers: Jenkins supports multiple build triggers, such as a commit to a version control system, or a schedule, which allows you to automatically start a build at a specific time or when certain conditions are met.

  • Rich set of reporting and analytics features: Jenkins provides a rich set of reporting and analytics features, which allow you to monitor the performance of your build process and identify any issues that need to be addressed.

  • Built-in web interface: Jenkins includes a built-in web interface, which allows you to manage and configure your Jenkins instance.

Did you find this article valuable?

Support Nikhil Chauhan by becoming a sponsor. Any amount is appreciated!