简体   繁体   English

Gerrit + Jenkins:在合并完成或放弃审核后如何触发操作?

[英]Gerrit + Jenkins: how to trigger an action after the merge is complete OR the review is abandoned?

I current trigger Jenkins builds on a git push to refs/for/ via the gerrit trigger in Jenkins (at the start of a review). 我当前的触发器Jenkins基于git在Jenkins中通过gerrit触发器推送到refs / for /(在评论开始时)。 This produces a build that is suitable for testing and verification prior to review completion. 这将生成一个适合在审核完成之前进行测试和验证的构建。 When the review is done (and any necessary rebasing is finished) the review is marked complete and this triggers the final merge of the code to Git (fast-forward only). 审阅完成(并且所有必要的变基完成)后,审阅被标记为完成,这将触发代码的最终合并到Git(仅快进)。

This works, but I'd prefer to park the build artifacts from Jenkins somewhere special until the review is finally merged, at which time that last build's artifacts go somewhere else (if the review is abandoned those artifacts would instead get purged). 这可行,但是我更喜欢将Jenkins的构建工件停放在特殊的地方,直到最终合并审阅,这时最后一次构建的工件会移至其他地方(如果放弃审阅,则这些工件将被清除)。

I thought I might create a special post-merge job in Jenkins and have it trigger on a merge, but since I want to trigger such a job if a branch is abandoned I don't think the merge trigger will cut it. 我以为我可能会在Jenkins中创建一个特殊的合并后作业,并在合并时触发它,但是由于如果分支被放弃,我想触发这样的作业,所以我认为合并触发器不会削减它。 Is there a gerrit/Jenkins trigger that'll help me automate this more exactly? 有一个gerrit / Jenkins触发器可以帮助我更准确地实现此自动化吗? (Currently we have a main build job per major component... but I might only need one global job that triggers for any merged component to handle the final disposition of said artifacts.) (当前,每个主要组件都有一个主要的构建作业……但是我可能只需要一个全局作业即可触发任何合并的组件来处理所述工件的最终处理。)

Jenkins has a trigger for "change abandoned" too. 詹金斯(Jenkins)也有引发“放弃变化”的诱因。

There's no problem having more than one Jenkins job per branch/change/commit/push, both with fire (and will return a combined comment on Gerrit so there's no extra email spam). 毫无疑问,每个分支/更改/提交/推送都有一个以上的Jenkins工作,而且都可以执行(并且会返回对Gerrit的合并评论,因此不会产生额外的垃圾邮件)。

You can create a new global jobs that will just trigger on merge or abandoned (just add both triggers). 您可以创建一个新的全局作业,该作业将在合并或放弃时触发(只需添加两个触发)。 Your build or post-build action can be a shell script or utility program that will do what you want. 您的构建或构建后操作可以是将执行所需操作的Shell脚本或实用程序。

There are also hooks ; 也有钩子 ; eg 例如

change-merged --change <change id> --change-url <change url> \ 
--project <project name> --branch <branch> --topic <topic> \
--submitter <submitter> --commit <sha1>

or 要么

change-abandoned --change <change id> --change-url <change url> \
--project <project name> --branch <branch> --topic <topic> \
--abandoner <abandoner> --reason <reason>

or a event stream where you can subscribe to, and trigger custom actions. 或您可以订阅并触发自定义操作的事件流

$ ssh -p 29418 review.example.com gerrit stream-events
{"type":"comment-added",change:{"project":"tools/gerrit", ...}, ...}
{"type":"comment-added",change:{"project":"tools/gerrit", ...}, ...}

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

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