Tech AI Insights

What Is a Jenkins pipeline?

When teams build software, one of the biggest challenges is making sure code moves smoothly from a developer’s laptop to production without constant manual work. This is where Jenkins comes in a popular open-source automation server that helps developers build, test, and deploy their applications.

And at the heart of Jenkins is something called a pipeline. If you’re new to Jenkins or DevOps, the term might sound intimidating, but don’t worry. In this blog, we’ll break it down into simple terms so you can understand exactly what a Jenkins pipeline is, why it matters, and how to use it.


What is a Jenkins Pipeline?

Jenkins should be used to build, test, and deliver your software.

For example:

  1. Get the code from GitHub.
  2. Compile it into an application.
  3. Run tests to make sure it works.
  4. Package it for deployment.
  5. Deploy it to a server.

These steps are written in a script (usually in a file called Jenkinsfile). Once you’ve set up the pipeline, Jenkins follows the steps automatically every time there’s new code. That means developers don’t have to manually run builds or worry about missing a step—Jenkins does it consistently.


Why Pipelines Matter

Before pipelines, teams often relied on manually running commands or using fragile scripts that only one person understood. That approach is:

  • Error-prone (easy to forget a step).
  • Hard to repeat (works on one machine but fails on another).
  • Slow (manual testing and deployment take time).

Pipelines solve these problems by:

  • Automating everything: No more manual clicks or commands.
  • Keeping it repeatable: Same process runs every time.
  • Making it visible: Everyone can see the pipeline and know where things stand.
  • Catching errors early: Automated testing spots problems before they reach production.

In short, pipelines help teams deliver software faster, safer, and with less stress.


Types of Jenkins Pipelines

Jenkins supports two main types of pipelines:

  1. Declarative Pipeline
    • Easier to learn and read.
    • Uses a structured syntax where you describe what should happen.
    • Great for beginners.

    Example:

    pipeline {
        agent any
        stages {
            stage('Build') {
                steps {
                    echo 'Building...'
                }
            }
            stage('Test') {
                steps {
                    echo 'Running tests...'
                }
            }
            stage('Deploy') {
                steps {
                    echo 'Deploying...'
                }
            }
        }
    }
    
    

    Here, you can clearly see the stages: Build, Test, Deploy.

  2. Scripted Pipeline
    • More flexible and powerful.
    • Uses Groovy scripting language.
    • Good for complex workflows.

    Example:

    node {
        stage('Build') {
            echo 'Building...'
        }
        stage('Test') {
            echo 'Running tests...'
        }
        stage('Deploy') {
            echo 'Deploying...'
        }
    }
    
    

    Both do the same thing, but the declarative pipeline is usually better for most teams starting out.

    Real Project example pipeline (this is the Declarative Pipeline)

    pipeline {
        agent any  // Use any available agent
    
        environment {
            NODE_VERSION = '20.x'          // Set the Node.js version
            PHP_VERSION = '8.4'            // Set the PHP version
            BACKEND_DIR = 'backend'        // Laravel directory
            FRONTEND_DIR = 'frontend'      // Vue directory
        }
    
        tools {
            nodejs NODE_VERSION            // Use NodeJS plugin
            php PHP_VERSION                // Use PHP plugin
        }
    
        stages {
            stage('Preparation') {
                steps {
                    // Checkout the code from the repository
                    checkout scm
                }
            }
    
            stage('Install Dependencies') {
                parallel {
                    stage('Install Laravel Dependencies') {
                        steps {
                            dir("${BACKEND_DIR}") {
                                // Install Composer dependencies
                                sh 'composer install --no-interaction --prefer-dist --optimize-autoloader'
                                sh 'php artisan config:clear'
                                sh 'php artisan config:cache'
                                sh 'php artisan route:cache'
                                sh 'php artisan view:cache'
                                sh 'php artisan migrate'
                            }
                        }
                    }
    
                    stage('Install Vue Dependencies') {
                        steps {
                            dir("${FRONTEND_DIR}") {
                                // Install npm dependencies
                                sh 'npm install'
                            }
                        }
                    }
                }
            }
    
            stage('Build Frontend') {
                steps {
                    dir("${FRONTEND_DIR}") {
                        // Build the Vue app for production
                        sh 'npm run build'
                    }
                }
            }
    
            stage('Deployment') {
                steps {
                    // Deploy your application here, this is an example command
                    // This can vary depending on your deployment strategy
                    echo 'Deploying application...'
                }
            }
        }
    
        post {
            always {
                // Clean up workspace after build
                cleanWs()
            }
    
            success {
                echo 'Pipeline succeeded!'
            }
    
            failure {
                echo 'Pipeline failed!'
            }
        }
    }
    
    

Key Concepts to Know

When learning Jenkins Pipeline, there are a few terms you’ll hear often:

  • Agent: An agent is where your pipeline runs. It could be your Jenkins server, a cloud agent, or a Docker container..
  • Environment: The environment block defines global environment variables that can be used anywhere in your pipeline.
  • Tools: The tools block ensures Jenkins uses the correct versions of your programming tools (like Node.js and PHP) from its tool configuration.
  • Stage: Stages are the big phases of your CI/CD pipeline. They divide your workflow into clear steps that Jenkins runs in order.
  • Step: Steps are the smallest actions Jenkins performs within a stage—like running a command or printing a message.
  • Post: The post section defines what happens after the pipeline finishes. It can run commands for cleanup, notifications, or logging—no matter if the pipeline succeeded or failed.

Think of it like this: A pipeline has stages, each stage has steps, and Jenkins runs them on an agent, all defined in a Jenkinsfile.

By learning pipelines, you’re not just using a tool you’re embracing a way of working that saves time, reduces errors, and helps software reach users faster.

So the next time someone mentions “CI/CD” or “automation,” you’ll know: pipelines are the backbone making it all possible.

For more insightful tutorials, visit our Tech Blogs and explore the latest in Laravel, AI, and Vue.js development.

Scroll to Top