Gerrit and maven release plugin

There is a time in your project when you start using Gerrit code review system. When you have maven release plugin to make release, you can be very surprised when you see:

1
2
3
[ERROR] The git-push command failed.  
[ERROR] Command output:
[ERROR] Permission denied (publickey).

This is a situation when we use ssh connections to gerrit. But, when you try to push something to master (ignoring code review), it works! How is that possible?

You probably have in your gitconfig an ssh URL with your user name. But in your project SCM (in pom.xml) you do not have your user name. What user name maven release plugin use? Your computer account name, which is in most cases different than your Gerrit user name.

How to repair it? Define a file in .ssh/config directory with content:

1
2
3
4
Host gerrit  
HostName YOUR_GERRIT_HOST
Port YOUR_GERRIT_PORT
User YOUR_GERRIT_USER_NAME

There may be a lot of other reason why you have Premission denied, but this was the hardest I’ve ever seen.