Skip to main content

Command Palette

Search for a command to run...

Pipeline as Code

Published
โ€ข3 min readโ€ขView as Markdown

1. Pipeline as Code kya hota hai?

Pipeline as Code ka matlab hai:

CI/CD pipeline ko UI me click-click karke banane ke bajay
code file me likhna aur usko repository me store karna.

Jenkins me is file ko bolte hain:
๐Ÿ‘‰ Jenkinsfile

Pipeline bhi code hai, jaise:

  • Application code

  • Infra code


2. Pehle ka problem (UI-based pipeline)

Traditional Jenkins job:

  • UI me steps add

  • Manual changes

  • Version history nahi

  • Team ko samajh nahi aata pipeline ka flow

  • Jenkins crash = pipeline gone


3. Pipeline as Code kyun use karte hain?

Main reasons (real world):

  • Pipeline ka version control

  • Code review possible

  • Reproducible builds

  • Team collaboration

  • Easy rollback

  • DevOps best practice

Isliye companies UI jobs avoid karti hain.


4. Pipeline as Code ka flow

Developer โ†’ Jenkinsfile โ†’ Git โ†’ Jenkins โ†’ Build/Test/Deploy
  • Jenkinsfile repo me hota hai

  • Code push hota hai

  • Jenkins Jenkinsfile read karta hai

  • Pipeline run hoti hai


5. Jenkinsfile types

Simple, clean, structured.

pipeline {  agent any  stages {    stage('Build') {      steps {        echo 'Building...'      }    }    stage('Test') {      steps {        echo 'Testing...'      }    }  }}

Industry standard yehi hai.


2๏ธโƒฃ Scripted Pipeline (Advanced)

Powerful but complex.

node {  stage('Build') {    echo 'Build'  }}

Freshers ke liye declarative enough hai.


6. Jenkinsfile kaha rakha jata hai?

  • Project ke root directory me

  • Naam: Jenkinsfile

  • No extension

my-app/ โ”œโ”€โ”€ src/ โ”œโ”€โ”€ pom.xml โ””โ”€โ”€ Jenkinsfile

7. Pipeline as Code ka use kaha hota hai?

  • CI pipelines

  • CD pipelines

  • Jenkins + GitHub

  • Jenkins + SonarQube

  • Jenkins + Nexus

  • Jenkins + Docker

  • Jenkins + Kubernetes

Matlab end-to-end automation.


8. Real CI pipeline Jenkinsfile example

pipeline {  agent any  stages {    stage('Checkout') {      steps {        git 'https://github.com/org/project.git'      }    }    stage('Build') {      steps {        sh 'mvn clean package'      }    }    stage('Test') {      steps {        sh 'mvn test'      }    }  }}

9. Pipeline as Code vs UI Pipeline

PointPipeline as CodeUI Job
VersioningYesNo
Code reviewYesNo
ReusabilityHighLow
RollbackEasyHard
Industry useHighLow

10. Interview one-liner

Pipeline as Code means defining CI/CD pipelines in code and storing them in version control, enabling versioning, collaboration, and repeatable automation.


11. Simple language summary

  • Pipeline bhi code hai

  • Git me store hoti hai

  • Jenkins khud pipeline read karta hai

  • Team ke liye visible hoti hai

  • Production ready approach hai