Structure of pipline code Overview
pipeline{
agent any
tools {
maven "MAVEN3.9"
jdk "JDK17"
}
stages {
stage
('Fetch code'){
steps {
git branch: 'atom', url:'https://github.com/hkhcoder/vprofile-project.git'
}
}
stage('Unit Test'){
steps {
sh 'mvn test'
}
}
stage('Build'){
steps {
sh 'mvn install -DskipTests'
}
post {
success{
archiveArtifact artifacts: '**/*.war'
}
}
}
}
}
Badhiya question hai. Ye wahi stage hai jahan DevOps actually clear hota hai.
Main isko 3 parts me samjhaunga:
Is pipeline code ka ek-ek line meaning
Kya ye CI/CD hai ya nahi
VS Code ka role kya hai. Code likhna vs copy karna
Calm, real-world way me.
1️⃣ Pipeline code ko line-by-line samjho
🔹 pipeline {
pipeline {
Ye batata hai ki ye Declarative Jenkins Pipeline hai.
Jenkins 2.x+ me mostly yahi use hota hai.
🔹 agent any
agent any
Meaning:
➡ Jenkins ka koi bhi available agent / node is job ko run kar sakta hai
Agar sirf ek server hai to wahi chalega.
Real life:
agent any→ basicagent { label 'linux' }→ advanced
🔹 tools
tools { maven "MAVEN3.9" jdk "JDK17"}
Meaning:
➡ Jenkins ko bolo:
Maven ka version MAVEN3.9 use karo
Java JDK 17 use karo
⚠ Important:
Ye names Jenkins → Global Tool Configuration me pehle se configured hone chahiye
Warna pipeline fail ho jayegi.
2️⃣ Stages ka real meaning
🔹 stages {
stages {
Pipeline ko logical steps me tod diya.
Har step = ek stage
❌ Tumhare code me ek mistake hai
Tumne likha:
stages('Fetch code')
Correct hota hai:
stage('Fetch code')
Sirf stage, plural nahi.
🔹 Stage 1: Fetch Code
stage('Fetch code') { steps { git branch: 'atom', url: 'https://github.com/hkhcoder/vprofile-project.git' }}
Meaning:
➡ Jenkins GitHub se code uthayega
➡ atom branch checkout karega
Real world:
Ye CI ka first step hai
Code change hota hai → pipeline trigger hoti hai
🔹 Stage 2: Unit Test
stage('Unit Test') { steps { sh 'mvn test' }}
Meaning:
➡ Maven unit tests run karega
➡ Agar test fail → pipeline fail
Ye pure CI hai.
CI = Continuous Integration
Matlab:
Har code change pe automatically test
🔹 Stage 3: Build
stage('Build') { steps { sh 'mvn install -DskipTests' }
Meaning:
➡ Project build hoga
➡ WAR file banegi
➡ Tests skip honge (kyunki pehle hi test ho chuke)
🔹 post { success }
post { success { archiveArtifact artifacts: '**/*.war' }}
Meaning:
➡ Build successful hua
➡ Jenkins WAR file ko store kar lega
Real use:
- Ye artifact aage deployment me use hota hai
3️⃣ Kya ye CI/CD hai?
✅ Ye CI hai
Kyuki:
Code fetch ho raha hai
Test run ho raha hai
Build ban raha hai
Artifact save ho raha hai
❌ Ye CD nahi hai
Kyuki:
Deploy nahi ho raha
Server pe copy nahi ho raha
Docker / Tomcat / AWS kuch nahi hai
CD add karne ke liye:
Example:
Tomcat pe deploy
Docker image push
Kubernetes deploy
Tab bolega:
End-to-end CI/CD
4️⃣ VS Code ka role kya hai?
❓ VS Code pe likhne ka matlab kya?
Simple:
➡ VS Code sirf editor hai
➡ Jenkinsfile likhne ke liye
Jenkins actually:
Code execute Jenkins server pe karta hai
VS Code sirf writing tool hai
❓ Code khud se likhna hota hai ya milta hai?
Real answer (industry):
✔ 70% code existing pipelines se
✔ 20% Jenkins docs se
✔ 10% khud likhte ho
Senior DevOps bhi:
Jenkins UI ka Pipeline Syntax Generator
GitHub ke sample Jenkinsfiles
Previous company pipelines
Use karte hain.