I have a pipeline job with the following rule:
Deploy:
rules:
- if: $CI_COMMIT_AUTHOR != "project <project25636_bot@example.com>" && $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"
changes:
- 'root/**/*'
As you can see, this job only runs on a successful commit if the commit author is NOT "project project25636_bot@example.com" and the folder root has changed.
Just some minor background what this is for: When a normal user adds some files to the root folder the pipeline should execute. However, there is also a bot user which saves files to this folder as well (via another job), when this bot "commits" I do not want it to execute this job hence the !=. The above rule works perfectly.
What I am trying to is remove the hard coding of the bot email address and build it using variables instead. The original code is more complex but for the sake of demonstrating and isolating where the issue is I have simplified it as follows:
If I change the above job to:
variables:
bot: "project <project25636_bot@example.com>"
Deploy:
rules:
- if: $CI_COMMIT_AUTHOR != "$bot" && $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"
changes:
- 'root/**/*'
It doesn't work - it always executes even for the bot user. I have even tried many variations of the variable like ${bot} but it never works, it is as if GitLab cannot compare variables against each other.
Before anyone asks why would I want to do this - as I said I have simplified the above to demonstrate where the issue lies, my real code dynamically builds the variable. When I couldn't get it working I started simplifying the code further until I got to where I am now.
What I have tried:
Changing the rule to (to accommodate the spaces in the string):
$CI_COMMIT_AUTHOR != $bot
$CI_COMMIT_AUTHOR != ${bot}
$CI_COMMIT_AUTHOR != "${bot}"
Can anyone explain where I am going wrong? Or does this seem to be an issue with GitLab?
Thanks,