I have following pipeline that is a template for others, that is why I want to assign CI_DEFAULT_BRANCH as default value to TARGET_BRANCH that can be then overriden by other branch name (develop, release etc.) if needed.
Preconditions:
Project default branch is master
Pipeline runs on master branch
variables:
TARGET_BRANCH: $CI_DEFAULT_BRANCH # The name of the project’s default branch. = master
stages:
- build
build:
stage: build
rules:
- if: '$CI_COMMIT_BRANCH == $TARGET_BRANCH' # CI_COMMIT_BRANCH is master
script:
- echo hello
- 'dir env:'
Using this approach the job is not included in the pipeline, but changing the variable like this:
TARGET_BRANCH: "master"
adds the job to the pipeline.
The script section has the command to list all variables and their values in powershell. Both CI_COMMIT_BRANCH and TARGET_BRANCH have value master in both cases, but still on the first scenario rules:if does not seem to be true. Can someone explain why?