Gitlab Ci 管道失败并显示:gitlab 规则中的语法错误-ci.yml

Gitlabci pipline failes with: syntax error in rules in gitlab-ci.yml

在下面的 gitlab-ci.yml 中,我在启动管道时遇到语法错误。其他分支中的规则相同,验证和其他管道作业 运行 很好。

语法不正确。 CI 配置已验证,包括使用 includes 关键字添加的所有配置。 更多信息 jobs:foo-bar-validation:rules:rule if invalid expression syntax

stages:
  - validation
  - sonar
  - release
  - environments
  - infrastructure-shared
  - build
  - infrastructure-by-environment
  - deploy
  - destroy

variables:
  DOCKER_PYTHON_IMAGE: "${CI_REGISTRY}/foo/bar/python-3.6:2.1.3"
  TERRAFORM_IMAGE: "${CI_REGISTRY}/foo/docker_images/terraform_1.0.1_common_utils:1.1.1"
  SEMANTIC_RELEASE_IMAGE: "$CI_REGISTRY/foo/docker_images/semantic-release_17.4.4"
  SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
  GIT_DEPTH: 0

include:
  # CI templates
  - local: templates/gitlab/index.yml
  # Sections
  - local: foo/.gitlab-ci.yml
  - local: bar/.gitlab-ci.yml

release:
  stage: release
  image: $SEMANTIC_RELEASE_IMAGE
  tags:
    - kubernetes
  script:
    - git fetch --all --tags
    - semantic-release
  rules:
    - if: $CI_COMMIT_BRANCH =~ /(develop|master)/ && $CI_PIPELINE_SOURCE == "push"
    - if: $CI_COMMIT_BRANCH =~ /(develop|master)/ && $CI_PIPELINE_SOURCE == "web"
    - if: $CI_COMMIT_TAG
      when: never

# ========================================================
# Sonar
# ========================================================
sonar-analysis:
  stage: sonar
  image:
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  cache:
    key: "${CI_JOB_NAME}"
    paths:
        - .sonar/cache
  script: 
      - sonar-scanner -Dsonar.organization=foo-sonar -Dsonar.python.coverage.reportPaths=coverage.xml -Dsonar.branch.name=${CI_COMMIT_BRANCH}
  tags:
      - kubernetes
  rules:
      - if: $CI_PIPELINE_SOURCE == "merge_request_event"
        when: never
      - if: $CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_PIPELINE_SOURCE == "web"
        changes:
          - microservices/foo/foo/**/*
      - if: $CI_COMMIT_TAG
        when: never
  dependencies:
    - foo-bar-validation


environment-variables-files:
  stage: environments
  image: $TERRAFORM_IMAGE
  environment:
    name: $CI_COMMIT_BRANCH/prepare
    action: prepare
  tags:
    - kubernetes
  script:
    # TODO: move to terraform base image
    - apk add coreutils
    - bash scripts/generate_envs.sh
  rules:
    - if: $CI_COMMIT_BRANCH =~ /(master|develop)/ && $CI_PIPELINE_SOURCE == "push"
    - if: $CI_COMMIT_BRANCH =~ /(master|develop)/ && $CI_PIPELINE_SOURCE == "web"
    - if: $CI_COMMIT_TAG
      when: never
  artifacts:
    name: 'env-variables-$CI_COMMIT_REF_NAME'
    expire_in: 5h
    paths:
      - .env

我通过将一个依赖文件与另一个分支进行比较找到了答案并解决了语法问题。