How to Build a CI/CD Pipeline with Jenkins: A Step-by-Step Tutorial

Jenkins is the leading open-source automation server for continuous integration and delivery. This tutorial shows you how to build a CI/CD pipeline with Jenkins using a declarative Jenkinsfile, enabling automated builds, tests, and deployments. You’ll move from setup to production in four straightforward stages.

Before starting, ensure you have Jenkins installed, a Git repository (GitHub or GitLab), and a deployment target such as a server or Docker host. We’ll create a pipeline as code, meaning the entire flow lives in your repository and is versionable, testable, and easy to maintain.

Article illustration

1. Install Jenkins and Required Plugins

Install Jenkins from the official site or use the Docker image. Then, you need essential plugins:

  • CloudBees Pipeline
  • Git
  • Docker Pipeline
  • Credentials Binding

2. Write Your Jenkinsfile

Create a file named Jenkinsfile in your repository root. Here is a minimal declarative example:

pipeline {
  agent any
  stages {
    stage('Build') { steps { sh 'build.sh' } }
    stage('Test') { steps { sh 'test.sh' } }
    stage('Deploy') { steps { sh 'deploy.sh' } }
  }
}

Key Stages to Include

  • Build: compile code and produce artifacts
  • Test: run unit and integration tests
  • Deploy: ship artifacts to staging or production

3. Configure Triggers with Webhooks

In your Git service, add a webhook pointing to your Jenkins server. Then create a Multibranch Pipeline project so Jenkins scans branches and pull requests automatically. Every push triggers the pipeline without manual effort.

4. Secure and Approve Deployments

Use the Credentials Binding plugin for tokens and SSH keys, and add an input step in the Deploy stage for manual approval before production. This prevents accidental releases and adds a human-in-the-loop check.

Conclusion

Building a CI/CD pipeline with Jenkins reduces errors, speeds up delivery, and gives you consistent release processes. Start with these four steps, then add advanced features like notifications, security scanning, and rollback for a fully production-ready pipeline.

sarah antaboga
Author: sarah antaboga

Leave a Reply

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