29

I want to add a "verified" label to my Gerrit project to allow Jenkins to verify that the code builds and passes its tests and so on.

I know I need to add a section to project.config as below:

[label "Verified"]
       function = MaxWithBlock
       value = -1 Fails
       value =  0 No score
       value = +1 Verified

However, how do I get to that file to edit it?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Inductiveload
  • 6,094
  • 4
  • 29
  • 55

2 Answers2

64

The project settings are kept in the Git repository for the project. You can edit them by cloning the project from Gerrit, making the change, committing and pushing back to Gerrit.

You can do this for any project, but if you want it to be inherited by all your projects, which you probably do, use All-Projects as the project.

mkdir gtproj
cd gtproj
git init
git remote add origin ssh://<USER>@<GERRITHOST>:29418/<PROJECT>
git fetch origin refs/meta/config:refs/remotes/origin/meta/config
git checkout meta/config

Then, make the change to the project.config file which will now be in the current directory.

Now, commit the change, and push back to the Gerrit repo:

git commit -a -m "Added label - Verified"
git push origin meta/config:meta/config

And that's it.


If you want to test it: assuming you were actually adding the Verified label, you can check it is working like this. First, make sure the refs/heads/* section of All-Projects (or whichever project you changed above) has Label-Verified -1/+1 set for the relevant groups. This allows the listed groups to verify.

Now, assuming you have a project called MyProject and a patchset reference, say 1,1, to verify:

ssh -p 29418 user@host gerrit review --project MyProject --message "'I just verified this patchset'" --verified +1 1,1

This should return more or less immediately. You should now see in the Gerrit web UI that the user you just logged in as over SSH has left a +1 verified review on that patch.


Credit: Cribbed from this blog post.

Sa'ad
  • 5,255
  • 2
  • 17
  • 21
Inductiveload
  • 6,094
  • 4
  • 29
  • 55
  • 1
    I was unable to add remote using git 2.1.0 with Gerrit 2.10 on Fedora 21, but I was able to clone the Gerrit _All-Projects_ project directly like this: `mkdir gtproj; cd gtproj; git clone ssh://@:29418/ .; git fetch origin refs/meta/config:refs/remotes/origin/meta/config; git checkout meta/config` -- I'm not gitty enough to be able to say why I had to do it this way, but wanted to leave a comment in case anyone else encountered a similar issue. – Steve HHH Feb 24 '15 at 23:33
  • 2
    PS. The error I received from Git when using the commands in this answer was: `error: unable to resolve reference refs/remotes/origin/meta/config: Not a directory` – Steve HHH Feb 24 '15 at 23:35
  • 2
    It might not have been the case when the answer was posted, but by Gerrit 2.12 you can edit the file through the web interface. Projects -> List -> All-Projects -> General -> Button "Edit Config" Once you edit the config file and save, you'll see a patch with your changes. Merge that patch and you're golden =) – user986730 Oct 04 '16 at 18:18
  • 1
    +1 for providing a way to push directly into the refs/meta/config branch without a code review! Our config had become messed up (a blocking label added without proper permissions to USE the label) such that we were unable to check in any changes to the config because we couldn't use the blocking label we added in previously. – Brad P. May 10 '17 at 17:05
  • 3
    I am not sure how I got into the bad state but I was getting `error: dst refspec meta/config matches more than one.` So I had to do `$ git push origin meta/config:refs/meta/config ` – Harry Mallon Sep 07 '17 at 13:29
  • fetch failed: fatal: couldn't find remote ref refs/meta/config – Mystic Apr 10 '23 at 09:25
10

You can configure your project config in the Gerrit UI.

You should follow the following steps:

  1. Launch your Gerrit UI.
  2. Login as admin.
  3. Go to projects > and click List.
  4. Select your project and click Edit config button.
  5. Paste your content and click save.
Laurel
  • 5,965
  • 14
  • 31
  • 57
Gogs
  • 129
  • 3
  • 8
  • 3
    I tried this way, but the step 5 will generate code review flow. Inside there, I publish it, but the code review flow for this "Edit `project.config`" is not finished. Therefore it doesn't affect. – Larry Cai Sep 18 '17 at 06:33