Setting Up a Jenkins Pipeline:

Jenkins is one of the most popular tools for automating the CI/CD pipeline. Learn how to configure and set up Jenkins to automate testing, building, and deployment of your applications.

What is Jenkins?

Jenkins is an open-source automation server widely used for Continuous Integration (CI) and Continuous Deployment (CD). It helps automate the process of testing, building, and deploying applications, which increases efficiency and reduces human error. Jenkins is highly versatile and can be used for automating a wide variety of tasks, such as software builds, tests, and deployments, as well as infrastructure provisioning.

Jenkins supports a broad range of plugins that integrate with numerous tools and technologies, making it extremely flexible for developers and DevOps teams. It allows you to seamlessly integrate with version control systems (like Git), build tools (like Maven and Gradle), testing frameworks (like JUnit), and cloud platforms (like AWS, Google Cloud, and Azure).

Prerequisites

Before setting up a Jenkins pipeline, ensure that you have the following prerequisites in place:

  • Jenkins Server – Install Jenkins on your local machine or on a server. Download Jenkins
  • GitHub or GitLab Repository – Ensure you have a repository with source code that Jenkins can pull from.
  • Basic Knowledge of CI/CD Concepts – Familiarity with the concepts of Continuous Integration and Continuous Deployment will be helpful.
  • Jenkins Plugins – Install relevant plugins like Git, Maven, or Docker depending on your needs. You can find plugins on the Jenkins Plugin Index.
Step 1: Install Jenkins

If you haven't already installed Jenkins, follow these steps:

  1. Visit the Jenkins Downloads Page and choose the version appropriate for your operating system.
  2. Install Jenkins by following the installation guide for your platform.
  3. Once installed, navigate to http://localhost:8080 (or the appropriate URL) in your browser.
  4. Unlock Jenkins by providing the initial administrator password found in the logs or the file secrets/initialAdminPassword.
Step 2: Create a New Jenkins Job

After installing Jenkins, the next step is to create a new job (pipeline) to automate the deployment process.

  1. Log in to your Jenkins dashboard.
  2. Click on New Item from the sidebar.
  3. Enter a name for your pipeline (e.g., "MyFirstPipeline") and select the Pipeline option, then click OK.
Step 3: Configure Your Pipeline

Now that you've created the pipeline, it's time to configure it to perform automated actions like code building, testing, and deployment. Follow these steps:

  1. Scroll down to the Pipeline section and under Definition, select Pipeline script.
  2. In the Script box, you will write the pipeline script using Jenkins’ domain-specific language (DSL), called Declarative Pipeline or Scripted Pipeline.
Example Pipeline Script (Declarative)
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                script {
                    // Add build commands here, e.g., Maven build
                    echo 'Building the application...'
                }
            }
        }
        stage('Test') {
            steps {
                script {
                    // Add test commands here, e.g., run unit tests
                    echo 'Running tests...'
                }
            }
        }
        stage('Deploy') {
            steps {
                script {
                    // Add deployment commands here, e.g., Docker or Kubernetes deploy
                    echo 'Deploying the application...'
                }
            }
        }
    }
}
                
Step 4: Save and Run the Pipeline

Once the pipeline script is configured, click Save to save your pipeline.

To run the pipeline, click Build Now in the job page. Jenkins will execute the stages in the pipeline, displaying logs for each step in the console output.

Step 5: Monitor the Pipeline

Jenkins allows you to monitor the pipeline’s progress in real-time. You can check the console output for detailed logs and debug information.

In the job dashboard, you can also view past builds, their status, and any associated artifacts or reports.

On this page