GitLab yaml issues with $CI_COMMIT_REF_NAME

Viewed 36

Hope someone can shed some light on the below if possible.

I have the below code in our yaml file for our pipeline and currently only have two branches dev and main.

workflow:
rules:
# Fix for bug: https://gitlab.com/gitlab-org/gitlab/-/issues/34756
- if: $CI_MERGE_REQUEST_ID
  when: never
- if: $CI_COMMIT_REF_NAME == "main"
  variables:                             
    TF_ENV: "prod"
    GOOGLE_APPLICATION_CREDENTIALS_SETTER: 'export GOOGLE_APPLICATION_CREDENTIALS=$$SERVICE_ACCOUNT_DEPLOY_PROD'
    MYSQL_DATASTREAM_PASSWORD: $MYSQL_DATASTREAM_PASSWORD_PROD
- if: $CI_COMMIT_REF_NAME != "main"
  variables: 
    TF_ENV: "dev"
    GOOGLE_APPLICATION_CREDENTIALS_SETTER: 'export GOOGLE_APPLICATION_CREDENTIALS=$$SERVICE_ACCOUNT_DEPLOY_DEV'
    MYSQL_DATASTREAM_PASSWORD: $MYSQL_DATASTREAM_PASSWORD_DEV

I'm trying to include a pre-prod branch in between the two branches but to start with I wanted to change the != "main" in the second if statement to == "dev" to be explicit with the variable check.

The problem is when I do this the pipeline in GitLab just circles every-time i do a merge request. I've echo'd the variable $CI_COMMIT_REF_NAME and it does come back with the value 'dev' so I'm at a loss as to why explicitly checking it to equals dev rather than not equal to main would be an issue?

Many thanks,

Mark.

0 Answers
Related