【问题标题】:Maven release with jenkins slave and Credentials : how to pass SCM credentials to maven?带有 jenkins slave 和 Credentials 的 Maven 版本:如何将 SCM 凭据传递给 maven?
【发布时间】:2017-05-31 09:49:16
【问题描述】:

我正在使用 Jenkins 主/从设置。我希望 Jenkins 有一个凭据信息“来源”。不是散落在各处的密钥/密码。

因此,我不想在 Jenkins 中定义我的 SCM(使用来自 Jenkins 凭据提供程序的凭据),然后又在 pom.xml/settings.xml/id_rsa.pem 中定义,具体取决于工作。每个人都喜欢以自己的方式做事,最终我们会得到到处都是密钥文件或密码的副本。迟早会有人将 pom 推送到公共 repo,我们的服务器就会被入侵......

我看不到将凭据从 Jenkins 中获取到 maven 发布插件可以使用它们的地方的可维护方式。我错过了什么? (尝试将标签推送到 git 时,maven 发布失败

[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] Permission denied (publickey).

)

我显然可以定义一个安装在包含 pem 的从站上的“文件”(我可以想到几种方法来做到这一点),但是当我们轮换密钥以记住它位于多个位置时,我遇到了维护难题。否则,快照工作一个月,然后发布失败,没有人能弄清楚为什么 mvn 突然无法推送到 git。

(注意只有密钥登录,没有密码)

【问题讨论】:

  • 如果你使用 git,你不能使用 SSH 密钥吗?
  • 是的,我正在使用 ssh 密钥。但是如何将 .pem 文件从“凭据”中取出并放到构建从属服务器上?
  • 你的回答当然是我想说的。 :) :)

标签: git maven jenkins release credentials


【解决方案1】:

花了一上午的时间试图弄清楚这一点,然后在“构建环境”部分找到“SSH 代理”复选框。勾选它,并提供正确的凭据,它就可以工作。 我考虑删除这个问题,但在阅读了许多其他高维护建议(涉及 .pem 文件的副本)之后,我想我会留下它。

【讨论】:

  • 对于那些没有看到 SSH Agent 选项的人,您只需要安装plugins.jenkins.io/ssh-agent 插件即可。我们说话时 mvn release 正在运行,并且由于这个答案,标签已成功制作。
  • 这是迄今为止我找到的最佳解决方案。谢谢十亿。
【解决方案2】:

为了使这项工作与 github 存储库一起工作,我必须安装 SSH 代理(如 @P_W999 建议的那样)并将以下配置添加到我的 pom.xml:

[...]
<build>
    <plugins>
        [...]
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.3</version>
            <configuration>
                <tagNameFormat>v@{project.version}</tagNameFormat>
                <checkModificationExcludes>
                    <checkModificationExclude>pom.xml</checkModificationExclude>
                </checkModificationExcludes>
            </configuration>
        </plugin>
        [...]
    </plugins>
</build>

<scm>
    <connection>scm:git:ssh://git@github.com/${mygithubusername}/${mygithubreponame}.git</connection>
    <developerConnection>scm:git:ssh://git@github.com/${mygithubusername}/${mygithubreponame}.git</developerConnection>
    <url>https://github.com/${mygithubusername}/${mygithubreponame}.git</url>
    <tag>v@{project.version}</tag>
</scm>
[...]

【讨论】:

    猜你喜欢
    • 2022-01-06
    • 1970-01-01
    • 2013-04-06
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    相关资源
    最近更新 更多