CampusFlow
DevOpsJenkins

Jenkins

The leading automation server for CI/CD. Pipeline as code, plugins ecosystem, distributed builds, and multibranch pipelines.

Pipeline as Code

Jenkinsfile defines the entire CI/CD pipeline in your repository. Stored alongside code, versioned, and reviewed via PRs.

  • Declarative: Structured pipeline syntax
  • Scripted: Groovy-based with full programmatic control
  • Shared Libraries: Reusable pipeline code across repos
  • Multibranch: Auto-discovers branches, creates pipelines

Multibranch Pipeline

1Configure Multibranch Pipeline pointing to repo
2Jenkins scans branches and discovers Jenkinsfiles
3Each branch gets its own pipeline run
4Webhooks trigger builds on push/PR
5Blue Ocean provides visual pipeline view

Jenkinsfile Example

pipeline {
    agent any

    stages {
        stage('Checkout') {
            steps {
                checkout scmGit(
                    branches: [[name: '*/main']],
                    userRemoteConfigs: [[url: 'https://github.com/org/repo.git']]
                )
            }
        }

        stage('Build') {
            steps {
                sh 'npm ci'
                sh 'npm run build'
            }
        }

        stage('Test') {
            steps {
                sh 'npm test'
            }
            post {
                always {
                    junit 'reports/**/*.xml'
                }
            }
        }

        stage('Deploy') {
            when {
                branch 'main'
            }
            steps {
                sh './deploy.sh'
            }
        }
    }

    post {
        success {
            echo 'Pipeline completed successfully!'
        }
        failure {
            echo 'Pipeline failed!'
        }
    }
}

Plugins

P
Git

Git integration for SCM checkout

P
Pipeline

Pipeline as code with Jenkinsfile

P
Blue Ocean

Modern UI for pipeline visualization

P
Docker

Build and run containers in pipelines

P
Kubernetes

Dynamic agent provisioning on K8s

P
Credentials

Securely manage secrets and keys

P
Slack

Send build notifications to Slack

P
JUnit

Parse and display test results

Agents

Static

Permanent agents (VMs, bare metal). Always available.

Dynamic (Cloud)

Agents provisioned on demand (Docker, K8s, EC2).

Controller

Built-in agent that runs on the Jenkins controller node.

Blue Ocean UI

Modern, visual interface for Jenkins pipelines. Provides pipeline editor, real-time visualization of stages, log views, and branch activity. Reduces complexity of traditional Jenkins UI.

Interview Questions

Q1: What is the difference between Declarative and Scripted Pipeline?
Declarative Pipeline uses a structured `pipeline { }` block with predefined sections (agent, stages, post). It is simpler and enforces a strict syntax. Scripted Pipeline uses Groovy-based DSL with full programmatic control — more flexible but harder to maintain. Declarative is the recommended approach.
Q2: How do you secure Jenkins?
Use Role-Based Access Control (RBAC) with the Role Strategy plugin to restrict permissions. Enable Agent-to-Controller security to prevent agents from executing arbitrary commands on the controller. Use credentials binding for secrets. Run Jenkins behind a reverse proxy with HTTPS. Regularly update plugins.
Q3: What is the Jenkins controller-agent architecture?
The Jenkins controller (formerly master) is the central server that schedules jobs, serves the UI, and stores configuration. Agents (formerly slaves) execute build tasks. The controller delegates work to agents to distribute load. Agents can be static (permanent VMs) or dynamic (provisioned on demand via Docker, K8s, or cloud plugins).
Q4: Explain multibranch pipelines and their benefits.
Multibranch Pipeline automatically discovers branches in a repository and creates a pipeline for each. It uses the Jenkinsfile from each branch. Benefits: automatic branch detection, per-branch configuration, automatic pull request builds, and integration with GitHub/GitLab webhooks for real-time feedback.