I have below regular expression that check whether we do not have --deploy in a commit message
deploy_review:
<<: *deploy_review_base
except:
refs:
- tags
- master
variables:
- $CI_COMMIT_BRANCH != "review" && $CI_COMMIT_MESSAGE !~ /^.*--deploy/
Now I want to check the opposite of this, that is I want to check where this string --deploy is present in a commit message. Opposite of above expression. is there a way to achieve this ?
Appreciate any help on this
Thanks,
To invert the matching logic, just use =~ instead of !~.
Though your current logic (using !~) checks that the regex pattern does not match. =~ is used to check if the regex pattern does match. You should double check your regex pattern works as expected.
Related
I would be very happy if someone could help me with the following issue.
I would like to run specific scripts only for tags starting with a given tag name.
The following rule works well for the tag 'wind-index' but what I need is a regex as I would like it to work also for tags such as 'wind-index_0.1'
rules:
- if: $CI_COMMIT_TAG == "wind-index"
when: always
I was expecting this to work but without success....
rules:
- if: $CI_COMMIT_TAG == \^wind-index\
when: always
I've tried all possible combinations with simple quotes, double quotes or \^wind-index.*\, none are working.
Any suggestion, help is more than welcome :-)
You need
/ as regex delimiters
== is equality comparison operator, you need a regex matching operator, =~.
You can use
rules:
- if: $CI_COMMIT_TAG =~ /^wind-index/
when: always
That should do the trick:
- if: $CI_COMMIT_TAG =~ /^wind-index/
Ok I need this to be working.
As postfix bodycheck go through each line...I need some sort of if else.
If this is subject line and I want to check subject and NOT subject:test.com to be true
(\bSubject:\b)(?!=\bSubject:test.com\b)
This is not working.
Sample line:
Subject:test.com - testing email
If the lookahead is supported, you could write the pattern as:
\bSubject:(?!test\.com\b).*
Regex demo
I am trying to make use of the rules: parameter to make a job only appear in a pipeline if specified users did the push. I dont want to define the list of users for each job, so I have the following global variable:
variables:
USER_LIST: "user1 user2 user3"
and in the job, I have the following:
rules:
- if '$USER_LIST =~ /$GITLAB_USER_LOGIN/'
when: on_success
- when: never
This does not appear to be working, as I suspect the regex pattern being used is not being replaced by the variable, and using $GITLAB_USER_LOGIN as the search string. If I use an explicit search:
rules:
- if '$USER_LIST =~ /user1/'
when: on_success
- when: never
then the pattern matches just fine.
NOTE: I am aware that GITLAB_USER_LOGIN is a protected variable. I get the same problem with GITLAB_USER_EMAIL too.
So the question is, how can I put a GITLAB predifined variable into a string that will be used for pattern matching?
You are using a variable and not a regular expression in your rule. So you don't need the slashes around the $GITLAB_USER_LOGIN variable. Try something like this:
rules:
- if '$USER_LIST =~ $GITLAB_USER_LOGIN'
I have more or less the same problem setup. The issues mentioned in the comments were addressed in 15.1, see https://docs.gitlab.com/ee/ci/jobs/job_control.html#store-the-regex-pattern-in-a-variable.
Nevertheless '$USER_LIST =~ /$GITLAB_USER_LOGIN/' still doesn't work. Also, if you define a variable like pattern: /$GITLAB_USER_LOGIN/ and use that in the way described in the documentation, it doesn't work.
'$USER_LIST =~ $pattern'
What works, but isn't the solution to your or my problem is defining pattern with a fixed pattern, like pattern: /user1/. Then it works if used like this:
'$USER_LIST =~ $pattern'
But obviously, I want to use the actual user, that tries to create a pipeline.
What works on my instance (15.4) is this:
'$GITLAB_USER_LOGIN =~ $USER_LIST'
I have no idea why, cos in my opinion this is no behaviour suggested by the documentation. I looked around in several places and found no documented examples of this use, but it works.
This job gets created with a delayed start:
variables:
pattern: "user"
string: "this contains user and other stuff"
show-env:
stage: env
tags:
- ops
rules:
- if: $pattern =~ $string
when: delayed
start_in: 15m
- when: always
script:
- env
And if you remove user from string and push it again, it gets executed right away.
And it also works when I define USERLIST in the project ci/cd variables and test that against $GITLAB_USER_LOGIN.
The documentation shows that the content matching regex should look like this:
$VARIABLE =~ /^content.*/
for your code you need to add ^ and .*:
rules:
- if '$USER_LIST =~ /^user1.*/'
when: on_success
- when: never
My workaround is to build an dynamic-child-pipeline where the variable within pattern already evaluated and inserted as constant string.
Is it possible to use a regex in karate if condition as below
eval if ( xx!=“#regex [0-9]{7}”) karate.log(“success”)
I wanted to execute a if statement, regex evaluation is passed . Above code doesn’t evaluate as regex . It simply prints the log
You can use karate.match():
* def test = '123'
* if (karate.match(test, '#regex [0-9]+').pass) karate.log('pass')
Please refer to the docs: https://github.com/intuit/karate#karate-match
Some of my repositories share a naming convention and thus have the same ending, e.g
tools2
subdirectory/tools2
subdirectory/etc/tools2
I want to match these repositories with a single regex (if possible) in my gitolite conf file.
#tools_repos = .*tools2
When I try to push this change, it gives me an error
FATAL: bad expansion '.*tools'
If I understand correctly my pattern needs to be a subset of
$REPONAME_PATT = qr(^\#?[0-9a-zA-Z][-0-9a-zA-Z._\#/+]*$);
$REPOPATT_PATT = qr(^\#?[[0-9a-zA-Z][-0-9a-zA-Z._\#/+\\^$|()[\]*?{},]*$);
Reading the documentation I came up with this regex
[a-zA-Z0-9].*tools2
but this solution does not match
tools2
Is there a simple way to match the repositories with a single regex?
If '?' is supported, you can try:
[a-zA-Z0-9]?.*?tools2
# or
[a-zA-Z0-9].*?t?ools2 (suggested by HamZa)
Maybe the non-greedy form would allow for tools2 to be matched.
The OP prakti reports this seems to work:
[a-zA-Z0-9]?.*tools2