SynfraCore
Synfracore
Start Learning
Navigation

Academies

Platform

RoadmapsLabsCertificationsInterviewPYQsAI AssistantCareer
Start Learning Free🗺️ Learning Roadmaps
Blog/DevOps

Jenkins Pipeline Tutorial 2026: From Zero to Production CI/CD

SynfraCore·April 2026·12 min read

Why Jenkins Still Matters in 2026

GitHub Actions and GitLab CI get all the attention, but Jenkins still runs CI/CD for the majority of enterprise production workloads. Banks, telecoms, healthcare — they built on Jenkins and it works. Knowing Jenkins is a guaranteed interview question at any enterprise DevOps role.

Your First Declarative Pipeline

groovy
// Jenkinsfile — place this in your Git repo root
pipeline {
    agent any

    environment {
        APP_NAME = 'myapp'
        DOCKER_REGISTRY = 'docker.io/myorg'
    }

    stages {
        stage('Checkout') {
            steps {
                git branch: 'main', url: 'https://github.com/org/myapp.git'
            }
        }
        stage('Build') {
            steps { sh 'mvn clean package -DskipTests' }
        }
        stage('Test') {
            steps { sh 'mvn test' }
            post { always { junit 'target/surefire-reports/*.xml' } }
        }
        stage('Docker Build and Push') {
            steps {
                withCredentials([usernamePassword(
                    credentialsId: 'dockerhub-creds',
                    usernameVariable: 'DOCKER_USER',
                    passwordVariable: 'DOCKER_PASS'
                )]) {
                    sh '''
                        docker build -t $DOCKER_REGISTRY/$APP_NAME:$BUILD_NUMBER .
                        docker login -u $DOCKER_USER -p $DOCKER_PASS
                        docker push $DOCKER_REGISTRY/$APP_NAME:$BUILD_NUMBER
                    '''
                }
            }
        }
        stage('Deploy to Kubernetes') {
            steps {
                sh '''
                    kubectl set image deployment/$APP_NAME \\
                        $APP_NAME=$DOCKER_REGISTRY/$APP_NAME:$BUILD_NUMBER
                    kubectl rollout status deployment/$APP_NAME
                '''
            }
        }
    }
    post {
        success { echo 'Deployment successful!' }
        failure  { echo 'Deployment failed!' }
    }
}

Key Jenkins Concepts

Declarative vs Scripted: Use declarative (the pipeline {} syntax) for 95% of use cases. Structured, validated, easy to read. Use scripted Groovy only when declarative cannot express the logic.

Agents: agent any runs on any available agent. agent { docker { image 'maven:3.9' } } runs the stage inside a Docker container — consistent build environment.

Credentials: Never hardcode passwords. Store in Jenkins Credentials Manager and reference with withCredentials().

Parallel Stages for Speed

groovy
stage('Tests') {
    parallel {
        stage('Unit Tests')        { steps { sh 'mvn test -Dtest=Unit*' } }
        stage('Integration Tests') { steps { sh 'mvn test -Dtest=Integration*' } }
        stage('Security Scan')     { steps { sh 'trivy image myapp:latest' } }
    }
}
// All three run simultaneously — cuts pipeline time by 60%

Common Failures and Fixes

Build fails on one agent but not another: Use Docker agents for consistent environments.

Pipeline hangs: Add timeout(time: 10, unit: 'MINUTES') to stages.

Secrets leaking in logs: Use the Mask Passwords plugin. Never echo passwords.

Workspace pollution: Add cleanWs() in post { always { ... } } to clean after each build.

See Jenkins Academy for the complete CI/CD learning path.

Found this useful? Share it:

Twitter / X LinkedIn WhatsApp Telegram

Weekly DevOps & Cloud digest

Every Sunday — tutorials, interview questions, tips, and what changed in DevOps and Cloud this week.

Join our Community
Daily tips, job alerts, interview help — join engineers learning together
← All articlesStart Learning DevOps