Jenkins gerrit trigger not fetching my change while building
Asked Answered
P

4

14

I have configured jenkins with gerrit trigger plugin to validate every commit we push to gerrit. I am expecting this trigger to include my latest change with original repo and make a build. But, it is cloning only repo project and compiling without my change.

Below is my configuration settings for gerrit trigger in jenkins.

Refspec: $GERRIT_REFSPEC 
Branches to build: $GERRIT_BRANCH 
Build trigger: Gerrit event 
Trigger on: patch set created 
Gerrit project: added project and branch

Below is the build output message

Triggered by Gerrit: http://ci-test1/22
Building on master in workspace /var/lib/jenkins/jobs/Build_Adserver_4.7/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Build_Adserver_4.7/workspace - hudson.remoting.LocalChannel@733aee56
Using strategy: Default
Last Built Revision: Revision 701a75ef38aa191ac1b806c48e6b3451671888f6 (ads/4.7)
Fetching changes from 1 remote Git repository
Fetching upstream changes from abc
Commencing build of Revision 701a75ef38aa191ac1b806c48e6b3451671888f6 (ads/4.7)
Checking out Revision 701a75ef38aa191ac1b806c48e6b3451671888f6 (ads/4.7)
[workspace] $ /bin/sh -xe /tmp/hudson1375188638196718521.sh
+ echo 'Started Build'
Started Build
+ echo ..................
..................
+ echo 'Build Finished'
Build Finished
Finished: SUCCESS

Here 701a75ef38aa191ac1b806c48e6b3451671888f6 is HEAD of repo branch and 8cbda558adcad4fb7eb714e0b3fb98a6fbf5811c is the SHA-id of my latest change trigged the build.

I verified from jenkins workspace also, it doesn't include my change.

sorry if I am missing any information to mention. Please let me know please help me if I am missing anything here.

Peggi answered 27/9, 2013 at 21:51 Comment(0)
U
10

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

Undeniable answered 30/9, 2013 at 0:43 Comment(8)
@uncletall, I am also facing this problem. I am using the latest versions now. I dont see "Choosing Strategy". As per the new version, I have configured "Gerrit Trigger" params properly. But still, my jenkins on old code. pls helpStarr
I am pretty sure it is there in the latest version. BUT! The git plugin is seriously broken at the moment. I had to downgrade the Git Client Plugin from 1.6.1 to 1.4.6 and the Git Plugin from 2.0.1 to 1.4.0 to get the Gerrit Trigger to work againUndeniable
Did you have to downgrade?Undeniable
Some more info would be very helpful, I'm also facing this problem with the latest. Did you have to downgrade?Opaline
Did you set the choosing strategy? I just saw your other answer, guess you managed to fix it.Undeniable
@Undeniable You may have to go to Additional Behaviours > Add > Strategy for choosing what to buildMighty
Guess that is on a new version of Git TriggerUndeniable
Thanks Richard, seems choosing strategy is now "Strategy for choosing what to build"Thickset
O
17

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

  1. Install the plugin(s) "Gerrit Trigger", "Git Plugin" and "Git Client Plugin"
  2. In the main jenkins config (HOME->Manage Jenkins), click on Gerrit Trigger.
  3. Create the server and configure it. Use "Test Connection" to be sure it works.
  4. At the end, under "Control" press "start" (No idea what that does or if it's actually needed, but I did that).
  5. Go to your project's config (MYPROJECT->Configure)
  6. Check "Gerrit event" under "Build Triggers"
  7. In the newly added menu, select your server, your triggers, etc.
  8. For Gerrit Project I used "Plain" with "MYPROJECT" as pattern
  9. For Branch, I used "Path" and "**" as pattern (builds all branches)
  10. Under "Source Code Management" (up from triggers in my UI), click on "Git"
  11. Set the Repository URL, here $USER matches for me, but otherwise write the correct user $GERRIT_SCHEME://$USER@$GERRIT_HOST:$GERRIT_PORT/$GERRIT_PROJECT
  12. Specify a branch: $GERRIT_BRANCH
  13. Under "Repositories" on the right, click Advanced, for "Refspec" enter $GERRIT_REFSPEC
  14. Click Add right below, and select "Strategy for choosing what to build"
  15. 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

enter image description here

Opaline answered 28/2, 2014 at 21:12 Comment(3)
Did you have to downgrade the git plugins?Undeniable
Didn't have to downgrade. I'm not using the very latest version of jenkins though. See my answer for exact version numbers.Opaline
Thank you very much. I am doing gerrit->jenkins->docker-pipeline, your answer is very helpful!Cryptography
U
10

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

Undeniable answered 30/9, 2013 at 0:43 Comment(8)
@uncletall, I am also facing this problem. I am using the latest versions now. I dont see "Choosing Strategy". As per the new version, I have configured "Gerrit Trigger" params properly. But still, my jenkins on old code. pls helpStarr
I am pretty sure it is there in the latest version. BUT! The git plugin is seriously broken at the moment. I had to downgrade the Git Client Plugin from 1.6.1 to 1.4.6 and the Git Plugin from 2.0.1 to 1.4.0 to get the Gerrit Trigger to work againUndeniable
Did you have to downgrade?Undeniable
Some more info would be very helpful, I'm also facing this problem with the latest. Did you have to downgrade?Opaline
Did you set the choosing strategy? I just saw your other answer, guess you managed to fix it.Undeniable
@Undeniable You may have to go to Additional Behaviours > Add > Strategy for choosing what to buildMighty
Guess that is on a new version of Git TriggerUndeniable
Thanks Richard, seems choosing strategy is now "Strategy for choosing what to build"Thickset
S
2

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

Seamy answered 1/12, 2017 at 18:30 Comment(0)
K
2

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.

Krissykrista answered 26/2, 2019 at 7:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.