I'm using a pipeline variable sent by the web pipeline creation as a condition to start a job. In my case, the variable contains the tags for the cucumber test cases that I would like to execute. If the tags don't match the job shouldn't be created in the pipeline.
What I was able to do is make it work when the tags are empty or the tags contains only one tag. At the moment I sent more than one tag the job doesn't start.
Reading the documentation I found that the '@' character should be replaced by /x40 for the regular expression. But, even having this in mind, I'm not able to do it. I know it should be a small detail and I cannot see it.
The example:
I send the next TAGS variable tag1 and tag2
The jobs are for example:
test-job1:
rules:
if: ($TAGS == null || $TAGS =~ /(\x40tag1|\x40tag3)(?!_)/)
script:
- echo "Multiple tags"
test-job2:
rules:
if: ($TAGS == null || $TAGS =~ /\x40tag2/)
script:
- echo "Single tags"
test-job3:
rules:
if: ($TAGS == null || $TAGS =~ /\x40tag1_Blabla/)
script:
- echo "Single tags"
What I expected is having the test-job1 running. But it is not. On the other hand, if I send the TAGS variable with tag1 the job starts.
I think the problem is (?!_) but I cannot see it.
What am I missing?
I'm using a pipeline variable sent by the web pipeline creation as a condition to start a job. In my case, the variable contains the tags for the cucumber test cases that I would like to execute. If the tags don't match the job shouldn't be created in the pipeline.
What I was able to do is make it work when the tags are empty or the tags contains only one tag. At the moment I sent more than one tag the job doesn't start.
Reading the documentation I found that the '@' character should be replaced by /x40 for the regular expression. But, even having this in mind, I'm not able to do it. I know it should be a small detail and I cannot see it.
The example:
I send the next TAGS variable tag1 and tag2
The jobs are for example:
test-job1:
rules:
if: ($TAGS == null || $TAGS =~ /(\x40tag1|\x40tag3)(?!_)/)
script:
- echo "Multiple tags"
test-job2:
rules:
if: ($TAGS == null || $TAGS =~ /\x40tag2/)
script:
- echo "Single tags"
test-job3:
rules:
if: ($TAGS == null || $TAGS =~ /\x40tag1_Blabla/)
script:
- echo "Single tags"
What I expected is having the test-job1 running. But it is not. On the other hand, if I send the TAGS variable with tag1 the job starts.
I think the problem is (?!_) but I cannot see it.
What am I missing?
Share Improve this question edited Mar 29 at 10:03 j.barrio asked Mar 28 at 7:24 j.barrioj.barrio 1,0581 gold badge15 silver badges38 bronze badges1 Answer
Reset to default 1The problem was that I was using a normal regex, and the rules for the if's in GitLab are using the Re2 Syntax, that can be validated in regex101 selecting Golang as Flavor.
At the end my regular expression fix was:
if: ($TAGS == null || $TAGS =~ /(\x40tag1|\x40tag3)\b/)
But it still didn't work until I used double back slash:
if: ($TAGS == null || $TAGS =~ /(\x40tag1|\x40tag3)\\b/)
After this everything worked perfect.
Hope it will be useful to someone.