Docs feedback: Workaround for regex on `only` for `external_pull_requests`
https://docs.gitlab.com/ee/ci/ci_cd_for_external_repos/
I discovered a difficulty with 2 pipelines created by GitLab CI/CD for branches connected to external pull requests (as listed in the documentation). This was disrupting my deployment process, as you can guess. In my specific situation, I was filtering branches by name with a regex so when I tried implementing the workarounds w.r.t. adding except: [branches], no pipeline would be created on a push. The inverse also didn't work, creating only: <regex> and except: [external_pull_requests] did not generate a pipeline. I tried the advanced only/except with
only:
refs:
- /<regex>/
- external_pull_requests
but that also didn't work. It ignored the regex and created pipelines for all external pull request changes
The workaround I used was to use only/except advanced with an AND, looking for the existence of the external pull request ID variable
only:
refs:
- /<regex>/
variables:
- $CI_EXTERNAL_PULL_REQUEST_IID
This created single pipelines on PRs with branches fitting the regex.
I don't know if this should be documented somewhere, but this seems like a common CI pattern, triggering builds based on a PR but choosing the type of job based on a branch name pattern (i.e. feature/foobar, release/foo, etc.)