git - Maven 发布/Github OAuth token /Jenkins : could not read Username for 'https://github.com' : No such device or address

标签 git maven github jenkins oauth

我正在尝试从 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/

相关文章:

git - Jenkins:凭据中私钥的正确格式是什么

java - Maven 如何与不同的存储库交互?

git - 如何在不同的注册用户下克隆一个 git private repo?

git - Jenkins checkout GIT 项目失败,权限被拒绝致命 : unable to fork

gitlab-runner : Add ssh key when executing locally

node.js - 无法在目录中运行程序 "npm"

git - 允许 Github 组织读取存储库

javascript - 我的网站图标代码不工作....我按照指南中所说的那样做了代码

android - 无法为 Salesforce 混合移动应用程序设置 ADT

java - 使用 filevault-package-maven-plugin 从包中排除节点