We're running a self-hosted GitLab CE instance. I'm trying to construct a very particular ruleset that works in our project environment. I'm aware of the basic building blocks: branch pipelines and MR pipelines, workflow:rules for pipelines, rules for jobs, predefined $CI_* variables, etc. I'm having trouble bringing them all together in a way that would also avoid duplicate pipelines, a common problem that may require very specific rule definitions to overcome.
We have a main branch from which feature branches are created, and merged back via merge requests. Occasionally some trivial fixes are pushed directly to main.
We've defined a pipeline with three jobs, currently all set to when: manual until we figure out this scheme. The eventual goal is this:
pre-build tests(stage:.pre)- Always runs as the first job, when the pipeline runs.
- Has
allow_failure: false– if the tests don't pass, no further jobs should run.
build(stage:build)- Conditions detailed below.
deploy to production(stage:deploy)- Should only be run manually in all situations.
- Has
dependencies: [build]
The conditions we'd like to have for the creation of the entire pipeline:
- A merge request for a feature branch is merged to
main: run the pipeline formain. - Commits are pushed directly to
main: run the pipeline formain. - (Side note: we want to prevent duplicate pipelines from the above two conditions.)
- Commits are pushed to a new or existing feature branch: run the pipeline for the feature branch. Does not matter if it has an open MR or not.
- All other cases (tags, new MR creation from/to any branch, etc.): DON'T run the pipeline.
If the pipeline runs, a couple of extra conditions for the build job specifically:
- The pipeline is running for the
mainbranch (via a push or an MR, doesn't matter): always build, assuming the tests passed. - The pipeline is running for a feature branch: must build manually.
Achieving this setup is probably not THAT many rules in total, but I'd like to not have to do hours of trial and error if this is something that an expert can readily help with.