GitLab Pages documentation for CI for environments non-working for default branch
Problem to solve
I believe this sample code is non-working because once you add one rule, you need to be sure to have one for each scenario. The rules shown do not contain rules that:
- Ensure that the job will run on the default branch
- Ensure that there are no duplicate jobs for MRs (works for both MR Pipelines and non-MR pipelines)
Snippets like this should be able to be grabbed and used directly whenever possible.
Further details
Proposal
To cover the scenario of default branch, I believe this is needed:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
PAGES_PREFIX: ""
I also feel that there should be at least (or only) one rule to handle all non-default branches - rather than a single rule to handle a hardcoded environment, like this:
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
variables:
PAGES_PREFIX: "$CI_COMMIT_REF_SLUG"
My complete rules section is like this - it makes explicit the empty mapping which might also simplify the rest of the example which has lines to default to blank.
rules:
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
variables:
PAGES_PREFIX: "$CI_COMMIT_REF_SLUG"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
PAGES_PREFIX: ""