Reputation: 17
I have the following .gitlab-ci.yml
configuration where I want the job update-environment
only to run on a push to main or on a MR to main.
Debugging the gitlab environment variables via printenv
I can see that both rules defined should evaluate to true
. But the job never runs. Does the job need to be defined in a stage or am I missing something?
default:
image: alpine
tags:
- "workstation"
validation:
script:
- |
echo "I will always run"
printenv # Checking GitLab Environment Variables
update-environment:
rules:
# - changes:
# - "*.yaml"
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "$CI_DEFAULT_BRANCH"'
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "$CI_DEFAULT_BRANCH"'
script:
- |
echo "Updating environment"
Upvotes: 0
Views: 2728
Reputation: 1417
Can you try with this
stages:
- check
- main
validation:
stage: check
script:
- |
echo "I will always run"
printenv # Checking GitLab Environment Variables
update-environment:
stage: main
rules:
# - changes:
# - "*.yaml"
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH'
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
script:
- |
echo "Updating environment"
I just added stages and removed quotes from CI_DEFAULT_BRANCH which you had added in the rules
Upvotes: 2