Skip to content

Fix CI rules-if comparison with Regexp variables

Furkan Ayhan requested to merge 35438-ci-variable-comparison-with-regexp into master

What does this MR do and why?

When the right side of a =~ or !~ comparison is a regexp variable, we consider this as a string. However, we need to try converting it to a regexp if possible.

In this MR, we start to try to consider the right side of an expression as a regexp.

Related to #35438 (closed)

This fix is behind a feature flag ci_fix_rules_if_comparison_with_regexp_variable (#359740 (closed)).

Screenshots or screen recordings

  1. Example CI pipeline config:
variables:
  teststring: 'abcde'
  pattern: '/^ab.*/'

test1:
  script: exit 0
  rules:
    - if: '$teststring =~ $pattern'

test2:
  script: exit 0
  rules:
    - if: '$teststring =~ /^ab.*/'
  1. Run a pipeline;

test1 is not included in the pipeline.

Screen_Shot_2022-04-18_at_13.08.31

  1. Enable ci_fix_rules_if_comparison_with_regexp_variable and run a pipeline;
Feature.enable(:ci_fix_rules_if_comparison_with_regexp_variable)

test1 is included in the pipeline.

Screen_Shot_2022-04-18_at_13.10.10

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Furkan Ayhan

Merge request reports