Configuring trunk-bot to use embedded Plastic code reviews
UPDATE June 15, 2020: We edited the blog post to use the new code review statuses (Under Review
instead of pending
, Reviewed
instead of approved
, and Rework Required
instead of discarded
).
Trunk-bot, one of the included mergebots, now takes into account code reviews and is able to merge reviewed branches only.
We are improving our built-in code review system, and we want to make it as easy as possible for you to take advantage of it. That's why we created Merge Rules, and why we have now enhanced the mergebots.
For those of you unfamiliar with mergebots, a mergebot is a piece of software that runs on your Plastic server and tries to merge task branches once they have met given criteria. Previously, mergebots only checked whether a branch had a given attribute, or if the associated Jira had a given status on it. Now we have added the branch review status into the mix, so you can easily incorporate code reviews into your CI/CD process.
Let's see how to configure this new setup.
Configuring trunk-bot to use code reviews
- Open the DevOps section in your Plastic SCM WebAdmin.
- Enable the Process reviewed branches only toggle button in trunk-bot configuration to activate this feature:
How does this feature work?
- When you create a code review for a tracked branch, or the existing code review status is changed, the task branch enters the trunk-bot queue. (You configure which branches are tracked using a prefix in the trunk-bot configuration).
- When trunk-bot dequeues this task branch, trunk-bot verifies that there is a code review for the branch, and that it's status is
Reviewed
, before continuing the CI cycle. If not, the branch processing is skipped and the branch is requeued. - If there is more than one code review linked to this task branch, all of them need to be
Reviewed
for the task branch to be processed. - If all the code reviews are
Reviewed
, trunk-bot will continue processing:- If the merge fails (manual conflicts are detected), or the branch build in the configured CI system fails, the status of the linked code reviews of the branch will be set to
Under Review
. - If the merge succeeds and the branch build succeeds too, the task branch is merged, and the "status" attribute of the branch is set to "merged" (these fields must be specified in the trunk-bot configuration).
- If the merge fails (manual conflicts are detected), or the branch build in the configured CI system fails, the status of the linked code reviews of the branch will be set to
You can use this Process reviewed branches only policy alone to drive the CI/CD cycle, or use the legacy "branch status" based lifecycle (Branch lifecycle configuration with a status attribute) to drive the process, or combine them.
If you combine them, before task branch is merged into trunk, both the status of the branch must be set to "resolved", and all the code reviews must be set to Reviewed
.
0 comentarios: