How to Set Up a CI/CD Pipeline with Jenkins: A Step-by-Step Guide

Jenkins is a powerful open-source automation server for building, testing, and deploying code. A robust CI/CD pipeline ensures consistent, reliable software delivery. This guide walks you through setting up a basic pipeline in Jenkins.

Before you begin, ensure you have Jenkins installed (via package manager or Docker), Java 8 or later, and a Git-based source control repository (e.g., GitHub, GitLab).

Article illustration

Step 1: Install Required Plugins

Plugins extend Jenkins functionality. For pipelines, install these essential plugins via Manage Jenkins > Manage Plugins:

  • Git Plugin – to pull source code
  • Pipeline Plugin – to create pipeline jobs
  • Blue Ocean Plugin (optional) – for a modern UI

Step 2: Create a New Pipeline Job

From the Jenkins dashboard, click New Item, enter a name, and select Pipeline. Avoid Freestyle projects; Pipeline jobs give full flexibility with scripted or declarative syntax.

Step 3: Define Your Pipeline Script

In the job configuration, scroll to the Pipeline section. Choose Pipeline script and paste a declarative template:

pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                git 'https://github.com/your-repo.git'
            }
        }
        stage('Build') {
            steps {
                sh 'mvn compile'
            }
        }
        stage('Test') {
            steps {
                sh 'mvn test'
            }
        }
        stage('Deploy') {
            steps {
                sh 'scp target/*.war user@server:/deploy'
            }
        }
    }
}

Replace commands and repository URL with your project details. Save the job.

Step 4: Trigger the Pipeline

Automate execution with one of these methods:

  • Webhooks – Add a webhook in your Git provider pointing to http://your-jenkins:8080/github-webhook/ (or GitLab/Bitbucket equivalents).
  • Poll SCM – In job config, under Build Triggers, check Poll SCM and set a cron schedule (e.g., H/5 * * * * for every 5 minutes).
  • Manual Trigger – Click Build Now from the job page.

With these steps, you now have a functional CI/CD pipeline. Expand it later with parallel stages, approvals, or environment-specific deployments. Automation saves time and reduces errors—start small and iterate.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *