From Jenkins I'm trying to do a maven release, with the code being hosted on github, on a repo. For the build user I generated an OAuth token to access the repo in RW mode.
In Jenkins I configured the repository checkout url like https://[email protected]/username/project
without any credentials, as the token in front should be enough.
In my pom, for the I did set any username/password, neither the token. The value is simply:
<developerConnection>scm:git:https://github.com/username/project</developerConnection>
But when maven is trying to push the commits on the pom files, I got an error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.1:prepare (default-cli) on project cloudstack: Unable to commit files
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] fatal: could not read Username for 'https://github.com': No such device or address
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.1:prepare (default-cli) on project cloudstack: Unable to commit files
Provider message:
The git-push command failed.
Command output:
fatal: could not read Username for 'https://github.com': No such device or address
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
Any idea how to fix that?
I've managed to solve this for the maven release plugin, with help from the Jenkins Credentials Binding Plugin. Note that this solution isn't needed for ssh authentication. Here's the SCM section in question:
<scm>
<connection>scm:git:http://${env.GIT_USERNAME}:${env.GIT_PASSWORD}@server.host.name/path/to/project.git</connection>
<url>http://server.host.name/path/to/project.git</url>
<tag>HEAD</tag>
</scm>
Then, I use the with credentials plugin, using the following in a Jenkins Pipeline script:
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'id-of-credentials-from-those-set-up-in-Manage-Jenkins',
usernameVariable: 'GIT_USERNAME',
passwordVariable: 'GIT_PASSWORD'
]]) {
performRelease()
}
Note that the env.GIT_USERNAME and the variable set up in withCredentials are the same, and that is no accident.
I must apologies though, as this solutions assumes familiarity with the Jenkins Pipeline Script.
You may be able to adapt this by setting the git credentials in the environment before running your own custom maven release plugin script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With