Sometimes when you submit patch to gerrit, you may have one or several gates running against the patch, verifying it has no issues, so it’s safe to merge it.
But what would you do if want to re-run all gates? usually I see developers using one of the following ways:
- go to the actual build page in jenkins and click on ‘retrigger all’
- comment in gerrit system with specific string
Rebase would work only if there is what to rebase on and using directly the build page on jenkins server will only work if you have account with permissions to access this jenkins server – so those two methods would be less convenient to use.
Option #3 is defiantly the way to go, but it’s also the option you won’t see available in every gerrit system like the other two.
Triggering on added comment is quick and flexible. The only required action by the developer is to add single comment on the gerrit page with the word chosen for retriggering jobs (e.g ‘recheck’)
So let’s see how you can add it in your own system:
First, note that this done per job and it’s not a global configuration. So you don’t must to apply it to all project/jobs.
Requirements: Make sure you have gerrit trigger plugin installed in version > 2.12.0 (Don’t know how? check Q&A below)
Choose the job you would like to trigger upon added comment and click on ‘configure’ in the job menu to enter its configuration.
After entering the job configuration page, go to ‘Gerrit Trigger’ section and press on the ‘Add’ button. You’ll see list of items to add. You should choose ‘Comments Added contains regular expression’.
The value you’ll enter would be “(?i)^(Patch Set [0-9]+:)?( [w\+-]*)*(nn)?s*(recheck)”
Let’s explain each part of this regex:
(?i) enable case sensitive expressions. So a comment starting with “Patch set” would work in our case, but not “patch set”.
^(Patch set) comment should begin (that’s the ^) with ‘Patch set’
[0-9]+ it also called greedy quantifier. It means the whatever before the + sign should appear at least one or more times. ‘Patch set 22:’ will work. but ‘Patch set : ‘will not.
[w\+-] * w stands for word. \ is actually one and the asterisk is anther ‘greedy quantifier’ that means ‘zero or more times’.
(nn)? n means ‘new line’ and there is double new line since it’s common to two new lines after “Patch set’ line. the ‘?’ is yet anther ‘greedy quantifier’ that means ‘once or not at all’. So having no new lines is also fine.
s*(recheck) the finale and quite important part. s is a space. we already discussed the asterisk. so s* means non or more spaces. (recheck) is the word should be written in order to trigger the build. you can choose whatever word you want. just make sure it makes sense for everyone if the job used by other people.
After posting the comment, the job should start running if queue is free 🙂
Q: how to check what gerrit plugin version I have on my Jenkins server?
A: In your jenkins server, in the left side menu click on ‘Manage jenkins’. In the new opened page, in the center, click on ‘Manage plugins’. You can see all installed plugins versions under the ‘Available’ view.
Q: how can I use several words in one regex liner?
A: you simply add pipe and anther word. for example: (?i)^(Patch Set [0-9]+:)?( [w\+-]*)*(nn)?s*(recheck|rerun|verify|run_all_gates)