Trigger pipeline if commit message matches a regular expression
Description
Reffering to the documentation Configuration of your jobs with .gitlab-ci.yml only
and except
options can be defined with regular expressions to trigger jobs. See only and except simplified and only and except (complex).
Problem
The regular expression only checks branches
and tags
but not the commit message.
I would like to set a regular expression that checks the commit message for a match.
Use Case
Depending on the branch we are working on, we change the test scope. In general, every branch is tested with some base tests.
Changes on our main branch master
have a higher test scope.
But sometimes and when working on a feature branch, we want to run the full pipeline of branch master
.
This would be easy using the commit message to trigger the pipeline:
git commit -m "[runfullpipeline]"
git push
if a corresponding regular expression is defined within .gitlab-ci.yml
.
Proposal
I think, extending the "filter search space" from tags
and branches
to tags
, branches
and commit-messages
would be the wrong approach because it could change the behaviour of existing pipelines and is not backward compatible.
But branches
(or commits more precisely) and tags
have both in common that you can add a commit message or annotation respectively.
Based on that thoughts, an additional option to configure a message
filter beside refs
and kubernetes
would ensure backward compatibility and is easy to use.
Examples
job:
only:
message:
- /\[runfullpipeline\]/
The example above runs the job if commit message or tag annotation contains [runfullpipeline]
.
job:
only:
refs:
- branches
message:
- /\[runfullpipeline\]/
The example above runs the job only if the commit message contains [runfullpipeline]
.
job:
only:
refs:
- master
message:
- /\[runfullpipeline\]/
The example above runs the job only on branch master
and only if the commit message contains [runfullpipeline]
.
Links / references
A similar question was asked before but the issue was closed because feedback of the author was missing, #33547 (closed). (I read the Issue tracker guidelines but couldn't figure out, if I shoud open a new if the issue exists but was closed because of missing feedback. :-))
Issue #23902 (moved) (Pipelines for Merge Requests) is open since 11 month and it seems that there won't be a solution in near future. Triggering pipelines using commit messages could be usefull in that case. This idea is directly related to the "run pipeline of master before merge into master" problem, but I think it is more useful to run the pipeline of master also during feature development (on demand).