MartyMacGyver
MartyMacGyver

Reputation: 10093

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). 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).

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).

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. Is there a gerrit/Jenkins trigger that'll help me automate this more exactly? (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.)

Upvotes: 0

Views: 7489

Answers (2)

eldur
eldur

Reputation: 254

There are also hooks; e.g.

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", ...}, ...}

Upvotes: 0

Motti Strom
Motti Strom

Reputation: 2735

Jenkins has a trigger for "change abandoned" too.

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).

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.

Upvotes: 3

Related Questions