尝试在Jenkins作业中为需要用户名/密码的Git存储库使用scm:tag

时间:2014-03-11 18:35:09

标签: git maven jenkins

我正在尝试按照Axel Fontaine(http://axelfontaine.com/blog/final-nail.html)的描述配置Jenkins / Maven / Git发布构建作业。我按照他的描述添加了我的POM,并相应地配置了我的Jenkins工作。

在源代码管理部分,我输入了我们内部托管的Stash实例的存储库URL(需要用户名和密码 - 不能选择SSH密钥):https://stash.mycompany.com/scm/st_proj/my_repo.git

我提供了用户名/密码凭证。

在博客文章中,我创建了一个具有目标versions:set -DnewVersion=$BUILD_NUMBER的Maven预备步骤。

同样在博客文章中,我将构建目标设置为deploy scm:tag

当作业执行时,我收到以下错误。

[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR]
(gnome-ssh-askpass:32706):  Gtk-WARNING **: cannot open display:
error: unable to read askpass response from '/usr/libexec/openssh/gnome-ssh-askpass'
fatal: could not read Username for 'https://stash.mycompany.com': No such device or address

我意识到这是因为Git命令试图提示我输入用户名和密码,但因为这是以Jenkins'作业没有显示它发送提示。

为什么在作业配置中先设置用户名和密码时,系统会提示我输入用户名和密码?我知道它们是正确的,因为他们需要克隆存储库。

3 个答案:

答案 0 :(得分:5)

另一个(也就是更好)的解决方案:

在Jenkins中,而不是使用scm:tag目标,使用Git Publisher后构建操作。在这里,您可以设置标签并将其推送到存储库,插件使用存储在Jenkins中的凭据!

Screen capture of Git Publisher section

答案 1 :(得分:3)

经过一段时间的冲击,我找到了一个解决方法 - 如果不是解决方案。 (仍然欢迎解决方案)

  1. 登录Jenkins构建从站(作为运行构建作业的用户)
  2. 设置凭据缓存git config --global credential.helper 'cache --timeout 600'
  3. 现在,当凭证用于克隆存储库时,Git会为后续的推送命令缓存它们。

答案 2 :(得分:0)

您还需要在maven中配置git凭据。

首先在<settings> <servers>

下的maven settings.xml 中声明服务器
<server>
    <id>gitserver</id>
    <username>git-user</username>
    <password>**************</password>
</server>

然后在项目 pom.xml 属性

中引用您的服务器
<project.scm.id>gitserver</project.scm.id>

请参阅http://maven.apache.org/maven-release/maven-release-plugin/faq.html#credentials