简体   繁体   English

如何让Jenkins Gerrit Trigger忽略我的CI用户的提交?

[英]How can I get Jenkins Gerrit Trigger to ignore my CI user's commits?

I want my code review job to ignore changes that came from other Jenkins job, like my release job for example. 我希望我的代码审查工作忽略来自其他Jenkins工作的更改,例如我的发布工作。 Those commits can be identified either by the committing user (preferable) or the commit comment string (also acceptable). 这些提交可以通过提交用户(首选)或提交注释字符串(也可接受)来标识。

Basically I have the same problem as the user who asked Ignore Jenkins job if commit message starts with a given string , except that I'm not using the Git plugin with polling. 基本上我遇到的问题是, 如果提交消息以给定字符串开头 ,请求忽略Jenkins作业的用户,除了我没有使用带轮询的Git插件。 Instead I'm using the Gerrit Trigger plugin , which gets triggered on each new change set. 相反,我正在使用Gerrit Trigger插件 ,它会在每个新的更改集上触发。

I believe the below screenshot includes the relevant configuration of the GT plugin. 我相信下面的截图包含了GT插件的相关配置。

I have searched around the web, but I couldn't find how to accomplish this. 我在网上搜索过,但我找不到如何做到这一点。 I found this kind of configuration for the Git plugin, but I can't use it since we're using Gerrit and so we need pre-commit changeset triggering rather than polling. 我找到了Git插件的这种配置,但我不能使用它,因为我们使用Gerrit,所以我们需要预先提交变更集触发而不是轮询。

触发“Patchset Created”,“Draft published”

Gerrit Trigger provides a group of variables in which you can find committer's name, commit message, etc. The solution I'm using is to test the values of these variables and end the build job if the test passes. Gerrit Trigger提供了一组变量,您可以在其中找到提交者的名称,提交消息等。我正在使用的解决方案是测试这些变量的值,并在测试通过时结束构建作业。 But there might be a problem if you are using Jenkins V2.3 or later. 但是如果您使用的是Jenkins V2.3或更高版本,可能会出现问题。 Some of the variables cannot be accessed via $ in shell. 有些变量无法通过$ in shell访问。 You can refer to Jenkins V2.3 release notes to solve this issue. 您可以参考Jenkins V2.3发行说明来解决此问题。 You could press the question mark right to Gerrit event to see the list of variables. 您可以向Gerrit event右侧按问号以查看变量列表。

One suggested approach was to use the "ci skip" plugin . 一种建议的方法是使用“ci skip”插件

I set up my release jobs to include [ci skip] in their commit messages. 我设置了我的发布作业,在其提交消息中包含[ci skip]。

When using it I found it actually still triggers a build. 使用它时我发现它实际上仍然触发了构建。 However, the build is exited as "Not Built", just after checking our the commit. 但是,在检查我们的提交之后,构建将退出为“Not Built”。 This means the build still clutters my build history, and it still consumes resources to fetch and rev-parse etc, so it is a less preferable solution to me. 这意味着构建仍然使我的构建历史变得混乱,并且它仍然消耗资源来获取和转发等等,因此对我来说这是一个不太优选的解决方案。

While this solves my immediate problem, I will happily accept other answers since I'm not entirely happy with this one. 虽然这解决了我的直接问题,但我很乐意接受其他答案,因为我对这个问题并不完全满意。

Actually, you can skip job execution using regex pattern in Gerrit topic configuration. 实际上,您可以在Gerrit主题配置中使用正则表达式模式跳过作业执行。

For example, you may not allow triggering job for change which topic has WIP word. 例如,您可能不允许触发更改哪个主题具有WIP字的作业。 This is possible using following regex ^((?!WIP).)*$ . 这可以使用以下正则表达式^((?!WIP).)*$

Here is an example how it trigger is implemented in our pipeline 以下是如何在我们的管道中实现触发器的示例

Gerrit trigger configuration: Gerrit触发器配置:

在此输入图像描述

Hope it will help. 希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM