Backend: GitLab CI/CD Components rules with input weird behavior
Update
This isnt a bug but but a documentation enhancement
When using variables without inputs:
rules:
- if: '"${ENVIRONMENT}" == "production"'
This will never evaluate to true no matter what value the $ENVIRONMENT
variable is set as, because the parser interpreter will not expand it.
When using variables with inputs:
spec:
inputs:
environment:
default: "${ENVIRONMENT}"
---
$[[ inputs.environment | expand_vars ]] Promote:
script: echo
rules:
- if: '"$[[ inputs.environment | expand_vars ]]" == "production"' # You can expand the variable here but you must quote the input block as well as the entire condition
The rules:if
clause can evaluate to true because we are expanding the variable with expand_vars
before the job's if
clause gets evaluated.
Summary
If I create a ci/cd component that accepts e.g. a branch name per input. Then it comes to a strange behavior.
Steps to reproduce
Create a ci/cd component with branchname input
spec:
inputs:
branch:
default: $CI_DEFAULT_BRANCH
---
job-name:
rules:
- if: $[[ inputs.branch ]] == $CI_COMMIT_REF_NAME
when: always
include:
- component: <...>
inputs:
branch: main # does not work
branch: $CI_DEFAULT_BRANCH # does work
(main is default branch)
What is the current bug behavior?
Unable to create pipeline
- jobs:job-name:rules:rule if invalid expression syntax
What is the expected correct behavior?
job should run
Edited by Dov Hershkovitch