I hope someone can help with this. I'm trying to configure the mvn release
plugin in pom.xml
so that the updated pom version and tag are pushed to the git repo as part of release:prepare
. Crucially, it needs to use the ssh private key of a specific user, as ultimately this will be part of our CI stack.
In the pom.xml
I currently have a very simple config for the release plugin:
<build>
<plugins>
<!-- release plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
</plugin>
The scm
settings in the pom look like this:
<scm>
<connection>scm:git:git://ssh@bitbucket.org/**account**/**project**.git</connection>
<developerConnection>scm:git:ssh://git@bitbucket.org/**account**/**project**.git</developerConnection>
<url>https://bitbucket.org/**account**/**project**</url>
</scm>
And I have the following property in the pom (though not sure if this is used or not - I found reference to it on a loosely related problem):
<properties>
<project.scm.id>bitbucket.org</project.scm.id>
Lastly, I have the following in mvn's settings.xml
:
<servers>
<server>
<id>bitbucket.org</id>
<privateKey>~/.ssh/bitbucket-read-write-access</privateKey>
<passphrase></passphrase>
</server>
The private key file ~/.ssh/bitbucket-read-write-access
exists, and there are no other keys in that folder (I have deliberately removed the default id_rsa
)
When I run mvn release:perform
, it fails when it tries to push to the repo:
[INFO] Executing: /bin/sh -c cd /home/nathanrussell/projects/**project** && git push ssh:********@bitbucket.org/**account**/**project**.git refs/heads/master:refs/heads/master
[INFO] Working directory: /home/nathanrussell/projects/**project**
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.162 s
[INFO] Finished at: 2018-11-09T15:25:36Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project **project**: Unable to commit files
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] git@bitbucket.org: Permission denied (publickey).
[ERROR] fatal: Could not read from remote repository.
[ERROR]
[ERROR] Please make sure you have the correct access rights
[ERROR] and the repository exists.
The only way I can get it to push correctly is to rename the file ~/.ssh/bitbucket-read-write-access
to ~/.ssh/id_rsa
which leads me to believe that:
- The user associated with the private key has the correct permissions on the repo and the public key is correctly associated with the repo user
- My configuration of the
pom.xml
and/orsettings.xml
is not quite right in respect of choosing/using the desired private key
(Before anyone suggests it, I cannot simply rename the key to ~/.ssh/id_rsa
because when we run this on the CI stack, it already has a default ssh key for another purpose)
Any thoughts or help with this would be very much appreciated
Some additional info:
If I do export GIT_SSH_COMMAND="ssh -i ~/.ssh/bitbucket-read-write-access"
then git push
, it pushes fine, which further leads me to believe the private/public key are correctly configured; and it's the mvn config that is wrong.