Jenkins gerrit trigger not fetching my change while building
Using Jenkins 1.532.2 Git Client Plugin 1.6.2 Git Plugin 2.0.1 Git Trigger 2.11.0
Here are the steps for configuring the Gerrit Trigger (from memory, hopefully all works fine):
- Install the plugin(s) "Gerrit Trigger", "Git Plugin" and "Git Client Plugin"
- In the main jenkins config (HOME->Manage Jenkins), click on Gerrit Trigger.
- Create the server and configure it. Use "Test Connection" to be sure it works.
- At the end, under "Control" press "start" (No idea what that does or if it's actually needed, but I did that).
- Go to your project's config (MYPROJECT->Configure)
- Check "Gerrit event" under "Build Triggers"
- In the newly added menu, select your server, your triggers, etc.
- For Gerrit Project I used "Plain" with "MYPROJECT" as pattern
- For Branch, I used "Path" and "**" as pattern (builds all branches)
- Under "Source Code Management" (up from triggers in my UI), click on "Git"
- Set the Repository URL, here $USER matches for me, but otherwise write the correct user $GERRIT_SCHEME://$USER@$GERRIT_HOST:$GERRIT_PORT/$GERRIT_PROJECT
- Specify a branch: $GERRIT_BRANCH
- Under "Repositories" on the right, click Advanced, for "Refspec" enter $GERRIT_REFSPEC
- Click Add right below, and select "Strategy for choosing what to build"
- Select "Gerrit Trigger"
Not very intuitive but it should work. I suggest making sure the correct SHA1 Ids are being built.
If run into Error stderr: fatal: Couldn't find remote ref $GERRIT_REFSPEC
Fixing small issues in Lewis answer, change the values to the following to ensure the latest SHA1 is built.
branch
: $GERRIT_REFSPEC
REFSPEC
: $GERRIT_REFSPEC:$GERRIT_REFSPEC
You have to change the Choosing Strategy
to Gerrit Trigger
Go to the configuration page of your job and then click on the 2nd Advanced
button under the git
section. Almost at the bottom there is a Choosing Strategy
that you will need to change to Gerrit Trigger
This will cause Git to fetch the correct version for your build
I am using Jenkins 2.15 and faced the Issue and got resolved with following settings.
In Git Advances add Refspec : $GERRIT_REFSPEC
Branches to build : $GERRIT_BRANCH
.
In Addititional behaviors section select Strategy for choosing what to build
and select gerrit Trigger
.