I try to run the step in CI/CD pipeline once the CHANGELOG.md file is not modified. This means that developers have not documented the changes being made in code. My intention is to fail the pipeline once it happens.
I wrote the following code but it doesn’t work:
.pre-verify:
stage: verify
tags:
- ubuntu-1804
- shell
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- "CHANGELOG.md"
when: never
script:
- echo "CHANGELOG.md is not updated."
- exit 1
When you push to a branch which has an associated MR, by default GitLab will start a pipeline for the branch AND a pipeline for the MR. The workflow keyword allows you to control when pipelines are created.
You probably don’t want that when: never at the end, most likely you want to think about things like tags, etc. first, but that set of rules says “create a pipeline for MRs, don’t create pipelines for branches or anything else”.