Skip GitLab CI Jobs for Documentation-Only Merge Requests
Stop running full test suites for docs-only merge requests. Learn how GitLab CI rules:changes compares file changes against the target branch and skips jobs safely.
16 Nov 2026, 05:05 UTC

Opening a merge request that only updates a README or a markdown guide should not trigger a ten-minute test suite. On GitLab.com or a self-managed instance, every pipeline run consumes CI minutes and runner capacity. If your team merges many small documentation changes, those runs add up quickly.
The useful takeaway: GitLab CI/CD's rules:changes compares the files touched by a merge request against the target branch by default. You can use that comparison to skip jobs when only documentation paths changed, and workflow:rules to prevent duplicate pipelines when a branch already has an open merge request.
How path-based rules evaluate merge requests
rules:changes accepts glob patterns and inspects the diff between the source branch and the target branch. In a merge request pipeline, GitLab compares the merge request's changes against the target branch, not against the previous commit on the source branch. That means a job with changes: ["docs/**/*"] runs only when something under docs/ differs from the target.
This is different from a branch pipeline, where GitLab compares against the branch's previous commit. A job skipped in a merge request pipeline might still run when the same commit is pushed directly to the branch. Test both contexts before you rely on skip logic.
Worked example: skip tests for docs-only changes
Add or edit .gitlab-ci.yml in the repository root. The following configuration runs the test job only when non-documentation files changed, and uses workflow:rules to avoid duplicate pipelines for branches with open merge requests.
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
test:
stage: test
script:
- bundle exec rspec
rules:
- changes:
- "docs/**/*"
when: never
- changes:
- "*.md"
when: never
- when: always
lint-docs:
stage: test
script:
- markdownlint docs/**/*.md
rules:
- changes:
- "docs/**/*"
when: always
- when: never
Here is what each part does:
workflow:rulessuppresses branch pipelines when an open merge request already exists for that branch, preventing duplicate runs for the same commit.- The
testjob useswhen: neverfor documentation globs. If onlydocs/or Markdown files changed, the job is skipped. Otherwise it falls through towhen: alwaysand runs. - The
lint-docsjob runs only when documentation changed, so you still validate docs edits without running the full suite.
Run this configuration from a feature branch, not directly on the default branch, unless you have permission to push to protected branches. Create a merge request against your default branch, then inspect the pipeline.
Verify before you rely on skip logic
- Open the GitLab CI Lint tool in your project editor (CI/CD > Editor > Lint). Paste the YAML and confirm there are no syntax errors. This validates the file without starting a pipeline.
- Add a temporary debug job that prints environment variables and the changed-files list, then run it on a merge request that changes only documentation:
debug-changes:
stage: test
script:
- echo "CI_MERGE_REQUEST_TARGET_BRANCH_NAME: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
- git diff --name-only $CI_MERGE_REQUEST_TARGET_BRANCH_NAME...$CI_COMMIT_SHA
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
Expected check: the diff should list only documentation paths, and the test job should show as skipped in the pipeline graph. Remove the debug job before merging.
After removing the debug job, compare pipeline graphs before and after the configuration change. Confirm that docs-only merge requests skip test while still running lint-docs. Check runner logs and job status in the GitLab UI to verify skipped jobs did not execute.
Limitations
rules:changescannot inspect merge-result diffs if the source branch is outdated relative to the target. Rebase the source branch or use a merge train for accurate path detection.- Broad glob patterns can skip jobs unintentionally. Narrow patterns can miss relevant files and fail to run required checks.
- CI minute savings are workload-dependent. The feature does not guarantee savings; it only prevents jobs from starting when the path conditions match.
Rollback
Committing .gitlab-ci.yml changes repository state. To roll back, revert the commit that introduced the configuration or push the previous version of the file, then confirm the pipeline graph returns to its earlier behavior.
Closing
Start with one job, such as your test suite, and apply rules:changes to documentation paths. Validate with CI Lint and a debug job on a real merge request. Once the skip behavior is consistent, expand to other jobs and monitor pipeline graphs for a few weeks to confirm the savings match your team's merge pattern.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.