Guides
GitLab CI Pipeline Beginners के लिए (.gitlab-ci.yml)
By Ravindra Bagale, DevOps trainer · LinkedIn · Published: · Last updated:
.gitlab-ci.yml में stages/jobs, Runner पर चलाएँ, artifacts रखें, red पर job log पढ़ें।
Friends, stages are the timetable, jobs are the workers. Chala mitrano — make test go green before build ships anything.
मित्रांनो, stages वेळापत्रक, jobs कामगार. Chala mitrano — build आधी test green करा.
मित्रों, stages समयसारणी, jobs कर्मचारी। Chala mitrano — build से पहले test green करें।
Quick answer
Hold this vertical picture:
- stages test/build.
- job scripts.
- artifacts.
- runner tag.
- push और pipeline.
Language: English · मराठी · हिंदी
GitLab CI flow
.gitlab-ci.yml क्यों
हर push के लिए एक YAML.
Why: Laptop drift.
What: stages/jobs on Runner.
How: repo root.
Example 1: Minimal .gitlab-ci.yml
Type this:
mkdir -p /tmp/glab && printf '%s\n' 'stages:' ' - test' ' - build' 'test_job:' ' stage: test' ' script:' ' - echo hello-test' 'build_job:' ' stage: build' ' script:' ' - echo hello-build' > /tmp/glab/.gitlab-ci.yml && cat /tmp/glab/.gitlab-ci.yml
You will see:
What it means: Stages run in order; jobs in a stage can run in parallel.
Example 2: Validate YAML shape
Type this:
python3 -c "import pathlib; t=pathlib.Path('/tmp/glab/.gitlab-ci.yml').read_text(); print('ok' if 'stages:' in t and 'script:' in t else 'bad')"
You will see:
What it means: Broken indentation is the number-one beginner failure.
Example 12: List stages mentally
Type this:
printf '%s\n' 'test then build then deploy — never deploy before test'
You will see:
test then build then deploy — never deploy before test
What it means: Order in stages: is the safety rail.
Concept 1: Artifacts/cache
Artifacts outputs; cache speed.
Why: बाद में dist नहीं.
What: artifacts paths.
How: dist/ save.
Example 3: Add an artifact
Type this:
printf '%s\n' 'build_job:' ' stage: build' ' script:' ' - mkdir -p dist && echo app > dist/app.txt' ' artifacts:' ' paths:' ' - dist/' > /tmp/glab/arti.yml && grep -A2 artifacts /tmp/glab/arti.yml
You will see:
What it means: Artifacts pass files to later jobs or downloaders.
Example 5: Cache node_modules pattern
Type this:
printf '%s\n' 'cache:' ' key: npm' ' paths:' ' - node_modules/' > /tmp/glab/cache.yml && cat /tmp/glab/cache.yml
You will see:
What it means: Cache speeds installs; artifacts ship outputs.
Example 8: Include a template file
Type this:
printf '%s\n' 'include:' ' - local: /ci/templates.yml' > /tmp/glab/include.yml && cat /tmp/glab/include.yml
You will see:
What it means: Shared templates keep many repos consistent at Capgemini.
Runner चुनें; main पर deploy.
Why: गलत tag = pending.
What: tags + rules.
How: branch gate.
Example 4: Runner tag idea
Type this:
printf '%s\n' 'test_job:' ' stage: test' ' tags:' ' - docker' ' script:' ' - echo on-docker-runner' > /tmp/glab/tags.yml && grep -A3 tags /tmp/glab/tags.yml
You will see:
What it means: Tags pick which GitLab Runner executes the job.
Example 6: only/rules sketch
Type this:
printf '%s\n' 'deploy:' ' stage: build' ' script: ["echo deploy"]' ' rules:' ' - if: \$CI_COMMIT_BRANCH == "main"' > /tmp/glab/rules.yml && cat /tmp/glab/rules.yml
You will see:
What it means: Run deploy only on main — Infosys teams expect branch rules.
Example 9: Variables block
Type this:
printf '%s\n' 'variables:' ' NODE_ENV: "test"' ' APP_NAME: "payments"' > /tmp/glab/vars.yml && cat /tmp/glab/vars.yml
You will see:
What it means: CI variables override without editing every script line.
Concept 3: Logs
Non-zero = fail.
Why: Log के बिना अनुमान.
What: job log खोलें.
How: before_script.
Example 7: Job log simulation
Type this:
printf '%s\n' 'hello-test' 'hello-build' > /tmp/glab/fake-log.txt && cat /tmp/glab/fake-log.txt
You will see:
What it means: Green jobs print script lines; red jobs stop at the failing line.
Example 10: before_script
Type this:
printf '%s\n' 'default:' ' before_script:' ' - echo prepare' > /tmp/glab/before.yml && cat /tmp/glab/before.yml
You will see:
What it means: Shared setup for every job under default.
Example 11: Exit code fails the job
Type this:
bash -c 'false; echo exit=$?' | tail -1
You will see:
What it means: Any non-zero script line fails the GitLab job.
GitLab CI card
1 stages 2 jobs 3 artifacts 4 tags/rules 5 job log
Suppose: yaml invalid
Indentation.
Suppose: pending
Runner tags.
Ravindra Bagale's Tip
At Infosys, a first GitLab merge request is often just test + build with artifacts. Reviewers open the job log.
Infosys मध्ये पहिला GitLab MR अनेकदा test + build + artifacts. Reviewers job log उघडतात.
Infosys में पहला GitLab MR अक्सर test + build + artifacts। Reviewers job log खोलते हैं।
Check yourself (quiz)
Q1. File?
.gitlab-ci.yml
Q2. Order?
stages list
Q3. Artifacts?
files between jobs
Q4. Pending?
no Runner tag
Q5. Red?
non-zero exit
Q6. rules?
when to run
Reading tracking
Mark this guide when you finish. Your browser remembers it on this device.
stages → jobs → artifacts → runner → green.
Did you understand? Let us try it once more.
Frequently asked questions
Where does the file live?
Repository root as .gitlab-ci.yml.
Stage vs job?
Stage is the phase; job is the work unit.
Artifacts vs cache?
Artifacts ship outputs; cache speeds repeats.
Why pending?
No Runner with matching tags.
How does a job go red?
Any script line exits non-zero.
Shared YAML?
include: local or project templates.