22/05/2026
⚙️ Advanced GitLab CI/CD – Rules & Logic
Production-level CI/CD Pipelines တွေမှာ pipeline job တိုင်းကို အမြဲ run နေစရာမလိုပါဘူး။
Branch, Tag, Environment, Trigger Type စတာတွေကိုကြည့်ပြီး logic ထည့်နိုင်ပါတယ်။
GitLab CI/CD မှာ rules, if, when တို့ကိုသုံးပြီး pipeline flow ကို smart control လုပ်နိုင်ပါတယ်။
📌 Why Use Rules & Logic?
✅ Unnecessary jobs မ run စေချင်တဲ့အခါ
✅ Production deploy ကို control လုပ်ချင်တဲ့အခါ
✅ Manual approval လိုချင်တဲ့အခါ
✅ Cost & pipeline time လျှော့ချချင်တဲ့အခါ
📌 Run Job Only on Main Branch
Production deploy jobs တွေကို main branch မှာပဲ run စေချင်ရင် 👇
deploy-prod:
stage: deploy
script:
- ./deploy.sh
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
📌 What Happens Here?
✅ main branch push ဖြစ်မှ deploy job run မယ်
❌ feature branches မှာ deploy မလုပ်ဘူး
ဒါက production safety အတွက် အရမ်းအသုံးဝင်ပါတယ် 🔥
📌 Manual Deployment (when: manual)
Production deploy ကို automatic မလုပ်ဘဲ approval ရပြီးမှ run စေချင်ရင် 👇
deploy-prod:
stage: deploy
script:
- ./deploy.sh
when: manual
📌 What Happens Here?
✅ Pipeline run ပြီး job က pause ဖြစ်နေမယ်
✅ GitLab UI ထဲက “Play” button နှိပ်မှ deploy စလုပ်မယ်
ဒါက safer deployment strategy တစ်ခုပါ 🚀
📌 Combine Rules + Manual
Main branch မှာပဲ manual deploy ဖြစ်စေချင်ရင် 👇
deploy-prod:
stage: deploy
script:
- ./deploy.sh
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: manual
📌 Real-World Use Cases
🚀 Production Deployment Control
🚀 Approval-based Releases
🚀 Scheduled Jobs
🚀 Environment-specific Pipelines
🚀 Skip unnecessary stages
📌 Best Practices
✔ Protect production deploy jobs
✔ Use manual approval for critical environments
✔ Keep deploy logic simple and readable
✔ Separate dev/staging/prod workflows
✔ Avoid duplicate pipeline runs