Skip to content

Regex issue in if: clause #1688

@Marakai

Description

@Marakai

Minimal .gitlab-ci.yml illustrating the issue

---
stages:
  - test

quoted-literal-rule:
  stage: test
  rules:
    - if: '"feature/JIRA-1234-something-broken" =~ /^renovate\/'
      when: always
  script:
    - echo "this job should never run on feature branches"

quoted-branch-rule:
  stage: test
  rules:
    - if: '"%{CI_COMMIT_BRANCH}" =~ /^renovate\/'
      when: always
  script:
    - echo "this job should only run for renovate/* branches"

Sample setup

Quick & dirty repo setup - intended to be copy-pasteable:

mkdir ~/gcl-re2-repro
cd ~/gcl-re2-repro

git init -q

echo "re2 repro" > README.md

cat > .gitlab-ci.yml <<'EOF'
stages:
  - test

quoted-literal-rule:
  stage: test
  rules:
    - if: '"feature/JIRA-1234-something-broken" =~ /^renovate\/'
      when: always
  script:
    - echo "this job should never run on feature branches"

quoted-branch-rule:
  stage: test
  rules:
    - if: '"%{CI_COMMIT_BRANCH}" =~ /^renovate\/'
      when: always
  script:
    - echo "this job should only run for renovate/* branches"
EOF

git add README.md .gitlab-ci.yml
git commit -qm "initial re2 repro"

git branch -M feature/JIRA-1234-something-broken
git remote add origin https://example.com/dummy/repo.git

Expected behavior

GCL should run without issues

Shown behavior

gitlab-ci-local --version

gitlab-ci-local --list

4.60.1 [ or 4.63.0 ]
Unable to retrieve default remote branch, falling back to `main`. The default remote branch can be set via `git remote set-head origin <default_branch>

                                                                                                              
Error attempting to evaluate the following rules:
  rules:
    - if: '"feature/JIRA_1234-something-broken" =~ /^renovate//'
as rhs contains unescaped quote

The remote branch complaint it because of faux git repo setup, not of concern here.

Host information

  • NAME="Linux Mint"

  • VERSION="22.1 (Xia)"

  • ID=linuxmint

  • ID_LIKE="ubuntu debian"

  • gitlab-ci-local: 4.60.1 and 4.63.0

Containerd binary

Using docker, but not in the context of this reproduction.

Additional context

It's strange to see the RE2JS complaint for 4.60.1, as the release notes said that wasn't introduced until 4.62.x ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    elaborateFurther elaboration is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions