4

I've installed the plugin Gerrit Trigger on Jenkins cos I need to start automatically the building when a developer in the team pushes something on the repository (relative to a specific project). I followed the settings here:

https://wiki.jenkins-ci.org/display/JENKINS/Gerrit+Trigger

The test connection is ok. Anyway when something is pushed the building doesn't "trigger". The only thing I can see is:

Under "Manage Jenkins" -> The connection to Gerrit is down! Check your settings and the Gerrit server.

any idea?

thanks

randomize

BTW I got this:

BTW I got this: Command "git fetch -t git@github.com:somewhere/MyProject.git $GERRIT_REFSPEC" returned status code 128: fatal: Couldn't find remote ref $GERRIT_REFSPEC fatal: The remote end hung up unexpectedly

 ERROR: Could not fetch from any repository
 FATAL: Could not fetch from any repository
 hudson.plugins.git.GitException: Could not fetch from any repository
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1008)
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:968)
at hudson.FilePath.act(FilePath.java:758)
at hudson.FilePath.act(FilePath.java:740)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:968)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1184)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:537)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:425)
at hudson.model.Run.run(Run.java:1376)
Randomize
  • 8,651
  • 18
  • 78
  • 133
  • I configured .../gerrit-trigger as in the above link. Then in "job/MyProject/configure" I set in "Source Code Management" under "Git" option $GERRIT_REFSPEC (although I don't know where this variable is set and how for default). Under the options: Gerrit Trigger I added "Plain:MyProject" with "Pattern:Plain:**" – Randomize Sep 28 '11 at 12:00
  • $GERRIT_REFSPEC is set by the Gerrit trigger with the refspec of the change, that is built. Did you start the build on your own with the "Build now" button, when you got that error? – dunni Sep 28 '11 at 13:09
  • Yes. As the "automatic" build doesn't start I tried with the manual launch. – Randomize Sep 28 '11 at 13:44
  • How do you resolve the configuration problem? I met it also, I can't save my changes for gerrit. – Kane Jul 11 '12 at 06:33

4 Answers4

3

There is trick described on the Gerrit plugin page:

Normally when you have configured a job to be triggered by Gerrit you can't use the "Build Now" link anymore since your builds are dependent on information from Gerrit, especially if you are using the Git plugin to checkout your code in the workspace.

You can get around this limitation if you for example want to use the same job to build the master branch at some point. If you are using the Git plugin do the following

Add a String parameter called GERRIT_REFSPEC with the default value refs/heads/master

Using this trick will enable you to build, but no results will be sent to Gerrit since tit is not triggered by it.

Wernight
  • 36,122
  • 25
  • 118
  • 131
  • This answer does not really address the root problem of Gerrit Trigger not properly talking to Gerrit, while "Test Connection" gives "Success". – Max Spring Feb 27 '14 at 05:39
0

in our case, we had to restart the jenkins service. this looks to be a bug with the gerrit trigger plugin (we're on 2.27.5)

mkumar118
  • 442
  • 5
  • 12
0

That doesn't work with the Gerrit trigger, because then the variable $GERRIT_REFSPEC isn't set. If you want to manually trigger a changeset from Gerrit, you have to use the "Query and Trigger Gerrit Patches". There you can search for open changes in Gerrit and build them.

You should also notice, that a build is only triggered, if you have pushed the changes to the review branches in Gerrit, e.g. a refs/for/ reference. If you pushed directly to the branches (e. g. refs/heads/master), because you don't want to do code review, the Gerrit trigger doesn't work. You would have to use one of the Gerrit hooks, that calls a URL which starts a build or let the build job poll your Git repository.

dunni
  • 43,386
  • 10
  • 104
  • 99
  • Do you know where to set variable 'GERRIT_REFSPEC'? – Kane Jul 12 '12 at 08:04
  • You have to insert the string '$GERRIT_REFSPEC' into the field refspec in the Git repositoriy configuration of the Jenkins job. The value of the variable will then be set automatically by the Gerrit trigger. – dunni Jul 12 '12 at 15:16
  • as far as i understand the question from Kane was about setting up the build now functionality in accordance to the doc of the gerrit trigger. THis is not about the refspec, but about build parameters ("this build is parameterized") section in job config – Eugene Sajine Aug 29 '14 at 20:37
-1

You Need to start the gerrit server from the jenkin>> gerrit trigger> click on status icon.

Rahul Rox
  • 11
  • 3
  • even though this sounds very simple, this is in fact a good solution. clicking the status icon makes the plugin to make a fresh connection to the gerrit server, which is akin to "restarting the computer". – mkumar118 Apr 10 '21 at 17:03