CI Validation false positive, checks before variable expansion
Summary
Gitlab CI environment:name
validation is overly strict. ${CI_COMMIT_REF_NAME#environment*/}
should be valid but isn't due to containing invalid characters.
Steps to reproduce
Validate the following gitlab-ci.yml
file
.environment_branches: &environment_branches /^environments?\//
deploy:
stage: deploy
script:
- echo 'deploying'
environment:
name: ${CI_COMMIT_REF_NAME#environment*/}
url: http://${CI_COMMIT_REF_NAME#environment*/}.example.com
only:
- *environment_branches
What is the current bug behavior?
${CI_COMMIT_REF_NAME#environment*/}
fails validation.
What is the expected correct behavior?
${CI_COMMIT_REF_NAME#environment*/}
should pass validation. For a branch named environments/dev
this should result in an environment:name
being dev
, which is valid. The validation doesn't appear to be checking a resulting value, it's checking the value before variable expansion.
On a side note, if I'm correct here, and unless validation is happening both before and after variable expansion, then using a variable with a bad character would NOT fail validation. In the example environments/dev
if the name was just ${CI_COMMIT_REF_NAME}
, after variable expansion the name would contain an invalid character.
Relevant logs and/or screenshots
Validator output:
Status: syntax is incorrect
Error: jobs:deploy:environment name can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', and spaces, but it cannot start or end with '/'