env:
global:
- ENV_BRANCH: "env-branch"
stages:
- name: One
if: branch = env(ENV_BRANCH)
- name: Two
if: branch = "env-branch"
jobs:
include:
- stage: One
install: skip
script: echo "Stage One depends on env()"
- stage: Two
name: Job Zero
install: skip
script: echo "Stage Two does NOT depend on env()"
- if: branch = env(ENV_BRANCH)
name: Job One
install: skip
script: echo "Job One depends on env()"
- if: branch = "env-branch"
name: Job Two
install: skip
script: echo "Job Two does NOT depend on env()"
Stage One, which depends on env() does not get built.
Stage Two gets built partially only as its Job One which depends on env() does not get built.
UPDATE
As pointed out by @native-api, ENV_BRANCH gets parsed as _BRANCH and changing the env var to SOMEBRANCH fixes the problem of the missing job but not the missing stage.
stages:
- name: deploy
# require the branch name to be master (note for PRs this is the base branch name)
if: branch = master
So what seems to not work is the above approach, meaning when the condition is included in the block stages to specify the ordering. If the condition is specified in the stage definition block then it works. Consider this config:
env:
global:
- SOMEBRANCH: "dev"
stages:
- if: branch = env(SOMEBRANCH)
name: One
- name: Two
if: branch = "dev"
- name: Three
if: branch = env(SOMEBRANCH)
- name: Hope
if: branch = env(SOMEBRANCH)
- name: Four
jobs:
include:
- stage: One
name: Job 0
install: skip
script: echo "Stage One depends on env()"
- stage: Two
name: Job Zero
install: skip
script: echo "Stage Two does NOT depend on env()"
- if: branch = env(SOMEBRANCH)
name: Job One
install: skip
script: echo "Job One depends on env()"
- if: branch = "dev"
name: Job Two
install: skip
script: echo "Job Two does NOT depend on env()"
- stage: Three
name: Hope
install: skip
script: echo "Stage Three depends on env()"
- if: branch = env(SOMEBRANCH)
stage: Four
name: Persevere
install: skip
script: echo "Stage Four depends on env()"