Lesstep
GitLab · CI/CD configuration · rules · Checked November 19, 2026

GitLab: an invalid variable expression in rules:if

This GitLab CI configuration is invalid followed by an expression error usually means a quoting mistake in a rules:if expression. In these expressions strings are quoted and variables are not (GitLab docs: job troubleshooting, checked November 19, 2026).

Valid

variables:
  ENVIRONMENT: production

job:
  script: echo
  rules:
    - if: $ENVIRONMENT == "production"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

To see the error next to the pipeline that failed: Pipelines and Jobs Inbox for GitLab CI, a plugin for JetBrains IDEs, shows under a pipeline that failed before any job ran the messages GitLab gives, such as a configuration error.

Invalid, and why

    - if: ${ENVIRONMENT} == "production"     # ${VAR} is not valid in if
    - if: "$ENVIRONMENT" == "production"     # the variable is quoted
    - if: $ENVIRONMENT == production         # the string is not quoted
    - if: "production" == "production"       # no CI/CD variable to compare

Fix

GitLab pipelines in IntelliJ IDEA

Pipelines and Jobs Inbox for GitLab CI, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, lists the pipelines of your GitLab projects with their jobs by stage. Under a pipeline that failed before any job ran it shows the messages GitLab gives (errorMessages), such as the configuration error, and it shows YAML errors as GitLab reports them, so you read the error without opening GitLab. After you fix the file, you can run a new pipeline on the branch from the IDE (Pro). Reading is free; retrying, cancelling and running are Pro (US$1.50 a month, with a 30-day trial).

Get it on JetBrains Marketplace

GITLAB is a trademark of GitLab Inc.; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by GitLab Inc. or JetBrains.

More: GitLab "Job may allow multiple pipelines to run for a single action" · GitLab "config contains unknown keys" · GitLab pipeline failed with no jobs · GitLab "config should be an array of hashes" (!reference)