Skip to main content

Command Palette

Search for a command to run...

GitLab part 3

Published
3 min read

1️⃣ Protected branches kya hoti hain?

Answer:
Protected branches wo branches hoti hain jahan direct push allowed nahi hota.
Sirf merge requests + approvals ke through changes jaate hain.
Production safety ke liye use hota hai.

Use case:
main branch ko protect kar do taaki koi directly push na kare.


2️⃣ Pipeline fail ho jaaye to kaise debug karte ho?

Answer:
Main job logs check karta hoon.
Error wali command ko locally run karke reproduce karta hoon.
Runner logs dekhta hoon agar runner issue ho.

One-liner:
Logs → reproduce locally → fix → re-run job.


3️⃣ Multi-stage pipeline kyu use karte hain?

Answer:
Build, test, deploy ko separate stages me rakhte hain taaki failures early pakad sakein.
Isse pipeline readable aur maintainable hoti hai.

Example:

stages: [ build, test, deploy ]

4️⃣ Artifacts ko expire kyu karte ho?

Answer:
Storage save karne ke liye artifacts ko limited time ke liye rakhte hain.
Purane artifacts automatic delete ho jaate hain.

Example:

artifacts:
  expire_in: 1 day

5️⃣ CI variables ko protected kyu set karte ho?

Answer:
Protected variables sirf protected branches par available hoti hain.
Isse secrets production ke alawa kahin leak nahi hote.


6️⃣ Job ko retryable kaise banate ho?

Answer:
Temporary failures ke liye job ko retry allow karta hoon.

Example:

job:
  script: ./deploy.sh
  retry: 2

7️⃣ Scheduled pipelines kya hoti hain?

Answer:
Cron jaise schedule par pipelines chalti hain.
Nightly builds, security scans ke liye useful.

Use case:
Roz raat ko tests run karna.


8️⃣ CI/CD me environment variables ka real use

Answer:
Different environments ke liye alag configs use karta hoon.
Jaise staging aur prod ke URLs.

Example:

variables:
  APP_ENV: "staging"

9️⃣ Monorepo me pipeline kaise handle karte ho?

Answer:
Folder-based rules lagata hoon taaki sirf related jobs run ho.

Example:

job:
  script: echo "run service A"
  rules:
    - changes:
        - services/service-a/**

🔟 GitLab CI Lint ka use

Answer:
.gitlab-ci.yml valid hai ya nahi, ye check karne ke liye CI Lint use karta hoon.
Syntax errors pehle hi pakad jaate hain.


🔥 Real-world scenario questions (with solution)

Q1. Sirf main branch pe deploy kaise karoge?

Solution:

deploy:
  stage: deploy
  script: ./deploy.sh
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'

Q2. MR par tests chalao, prod deploy mat chalao

Solution:

test:
  stage: test
  rules:
    - if: '$CI_MERGE_REQUEST_ID'

deploy:
  stage: deploy
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'

Q3. Pipeline ko fast kaise banaoge?

Solution ideas:

  • Cache use karo

  • needs use karo

  • Parallel jobs chalao

Example:

test:
  stage: test
  needs: [ build ]

Q4. Secrets leak hone se kaise bachaoge?

Solution ideas:

  • Secrets ko CI variables me rakho

  • Masked + protected enable karo

  • Logs me echo mat karo


Q5. Build fail hone par Slack/Email notify kaise karoge?

Solution:
Webhook ya notification integration use karo.
Fail condition pe notification bhejo.


🎯 1-minute interview ready answer

Main GitLab CI pipelines ko stages aur jobs me design karta hoon.
Runners par jobs run hoti hain.
Artifacts se outputs share karta hoon, cache se performance improve karta hoon.
Secrets CI variables me secure rakhta hoon.
Production deploy manual aur protected branches par karta hoon.
Rules aur needs se pipeline fast aur controlled banata hoon.