GitLab CI/CD lets you defineDocumentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
rules at both the job and workflow levels. While job-level rules determine whether an individual job runs, workflow-level rules control if the entire pipeline is created. This approach helps you:
- Dynamically set variables.
- Match branch patterns using regex.
- Filter pipelines by file changes.
Prerequisites
- Create a new GitLab project under your
demosgroup. - Name it
generic-project(public) and initialize with aREADME.md. - Open CI/CD > Editor to configure your pipeline.


1. Initial Pipeline Configuration
Add a minimal.gitlab-ci.yml to ensure your project has a pipeline:

rules to change that.
2. Rule 1: Run Only on main
Trigger the pipeline only for pushes to main, and set DEPLOY_VARIABLE to PRODUCTION:
main:
3. Rule 2: Merge Requests from feature/*
Only run pipelines on merge requests whose source branch matches feature/*. Use the predefined variable CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:

feature/my-awesome-feature and create an MR:

4. Rule 3: File-Change Filtering
Use thechanges: keyword to trigger pipelines only when certain files are modified. For example, run MR pipelines only if README.md changes:
README.md in your feature branch and push. Now you’ll see a new pipeline:

TESTING variable:
Summary of Workflow-Level Rules
| Rule | Trigger | Variable | Description |
|---|---|---|---|
| 1 | CI_COMMIT_BRANCH == "main" | PRODUCTION | Only build on main |
| 2 | MR event & source branch matches feature/* | TESTING | Run on feature-branch merge requests |
| 3 | Same as Rule 2 and changes: [README.md] | TESTING | Only when README.md is updated in the MR branch |
The first matching rule wins. If no rule matches, the pipeline won’t be created—no jobs will run.
Final .gitlab-ci.yml Example
Customize your
rules with when: manual, allow_failure, or file filters to match your team’s workflow.