我正在尝试从 Jenkins 发布一个 Maven 版本,代码托管在 github 上的一个 repo 上。对于构建用户,我生成了一个 OAuth token 以在 RW 模式下访问存储库。
在 Jenkins 中,我配置了像 https://token@github.com/username/project
这样的存储库 checkout url,没有任何凭据,因为前面的 token 就足够了。
在我的 pom 中,我没有设置任何用户名/密码,也没有设置 token 。值很简单:
<developerConnection>scm:git:https://github.com/username/project</developerConnection>
但是当 maven 试图将提交推送到 pom 文件时,我得到了一个错误:
[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)
知道如何解决这个问题吗?
最佳答案
在 Jenkins Credentials Binding Plugin 的帮助下,我已经设法为 maven 发布插件解决了这个问题。请注意,ssh 身份验证不需要此解决方案。 这是有问题的 SCM 部分:
<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>
然后,我使用 with credentials 插件,在 Jenkins 管道脚本中使用以下内容:
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'id-of-credentials-from-those-set-up-in-Manage-Jenkins',
usernameVariable: 'GIT_USERNAME',
passwordVariable: 'GIT_PASSWORD'
]]) {
performRelease()
}
注意 env.GIT_USERNAME 和 withCredentials 中设置的变量是一样的,这绝非偶然。
但我必须道歉,因为此解决方案假定您熟悉 Jenkins 管道脚本。
在运行您自己的自定义 maven 发布插件脚本之前,您可以通过在环境中设置 git 凭据来调整这一点。
关于git - Maven 发布/Github OAuth token /Jenkins : could not read Username for 'https://github.com' : No such device or address,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35484299/