Gerrit Basic Operations

Creating a project

In order to create a new project in Gerrit, log in with your previously created account. Then, select the "Projects" tab in the top bar and hit "Create New Project".

Next, enter a name for your project.

After that, choose the rights to inherit from:
If this is the first project you can just inherit from the default "all projects". You can also create a new project just to serve as a parent for other projects which then inherit the settings of the parent project.

Cloning the project

From the "Projects" selection in the top bar, you can see a list of all projects by clicking onto "List" below. After clicking on one of them you'll see the options page for this project.
In the project options page you can see (amongst other settings) the URL to use for cloning the Git repository like you would normally do.

Deleting projects

Deleting projects isn't possible by default (Gerrit prevents you from deleting projects because they have dependencies among themselves. Thus, deleting one project in the chain could have severe ramifications for other projects).

Permissions

Can be set for groups, project owners, admins and registered users in "Projects" > "Access". Permissions include things like: Who is allowed to read, push or submit changes. In addition it can be defined, how much influence certain groups should have over the reviewing process. Permitted users can create projects.

You can see some of the access restrictions that we defined for our project in the screenshot below. Among the important ones are:

project_access_settings_gerrit.png

How to edit project.config in a Gerrit project?
How to edit the project.config for all Projects in Gerrit?

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. you should have the project.config in you temp folder. Add the label as below:

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

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.

Reference
https://blog.bruin.sg/2013/04/how-to-edit-the-project-config-for-all-projects-in-gerrit/
https://stackoverflow.com/questions/22229536/edit-project-config-in-a-gerrit-project

How to install the verified label either globally?

How to install the verified label either globally (using init command [1]) or in your project [2]

- install the verified label either globally (using init command [1]) or in your project [2]
- configure permissions to only let Jenkins vote on verified label [3]
- this will block submit until Jenkins voted +1 on verified

[1] https://gerrit-review.googlesource.com/Documentation/install.html#init
[2] https://gerrit-review.googlesource.com/Documentation/config-labels.html#label_Verified
[3] https://gerrit-review.googlesource.com/Documentation/access-control.html#examples_cisystem

How to enforce developers group to perform the code review?

On the ACL, you will have to restricted Push rights only on reference map refs/for/* for developer group which forces developers to perform the code review.

How to create a change-ids

Change-Ids are created at commit time on the client side. A standard 'commit-msg' hook is provided by Gerrit, and can be installed in the local Git repository to automatically generate and insert a Change-Id line during git commit, when none is defined yet.

To install the hook, copy it from Gerrit’s daemon by executing one of the following commands while being in the root directory of the local Git repository:

$ curl -Lo .git/hooks/commit-msg http://review.example.com/tools/hooks/commit-msg

or:

$ scp -p -P 29418 john.doe@review.example.com:hooks/commit-msg .git/hooks/
Then ensure that the execute bit is set on the hook script:

$ chmod u+x .git/hooks/commit-msg

 

 


  Call us on +91 700 483 5930   |   +91 700 483 5706     Contact@DevopsSchool.com