Pipeline as Code

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
1๏ธโฃ Declarative Pipeline (Recommended)
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:
JenkinsfileNo 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
| Point | Pipeline as Code | UI Job |
| Versioning | Yes | No |
| Code review | Yes | No |
| Reusability | High | Low |
| Rollback | Easy | Hard |
| Industry use | High | Low |
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