Skip to content

Invalid expression syntax error for long rules:if configurations

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

When you have a long expression for rules:if, the CI configuration validation can fail with an error such as:

This GitLab CI configuration is invalid: jobs:job1:rules:rule if invalid expression syntax 

Splitting up your configuration and limiting the expression will make the error go away. Other variations of the same expression result in the same type of error.

Steps to reproduce

  1. Create a new GitLab project and commit a .gitlab-ci.yml file with content like the below:
.skip_dast:
  rules: &skip_dast
    - if: '(
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test"
      ) 
      && $SKIP_DAST == "1"
      '
      when: never

.test_rule:
  rules:
    - *skip_dast

stages:
  - a:testing

job1:
  stage: a:testing
  extends:
    - .test_rule
  script:
    - echo "does nothing"
  • The actual paths for CI_PROJECT_PATH shouldn't matter, the results are the same regardless of the path.
  1. You can remove one line until the error disappears.

Example Project

https://gitlab.com/gitlab-gold/cbledsoe-test/test-328353/-/blob/main/.gitlab-ci.yml

What is the current bug behavior?

A long rules:if expression results in a This GitLab CI configuration is invalid error.

What is the expected correct behavior?

If there is a validation error or limit, we should provide a specific error. Otherwise, we should fix the validation to allow the long expression.

Relevant logs and/or screenshots

Output of checks

GitLab.com 15.7.0-pre 6869a73e

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Workaround

You can create two sets of rules instead. For example in the above, you can do:

.skip_dast:
  rules: &skip_dast
    - if: '(
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
    ...<truncated>...
.skip_dast_2:
  rules: &skip_dast_2
    - if: '(
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
      $CI_PROJECT_PATH == "gitlab-gold/cbledsoe-test/scheduled-pipelines-test" ||
    ...<truncated>...
Edited by 🤖 GitLab Bot 🤖