【问题标题】:Where to keep a GPG secret key for Jenkins running on Windows?在哪里保存在 Windows 上运行的 Jenkins 的 GPG 密钥?
【发布时间】:2014-01-20 18:26:57
【问题描述】:

我正在尝试使用 Jenkins 将我的工件发布到 OSS Sonatype Nexus 服务器。但是在尝试对工件进行签名时出现以下错误。我已经生成了我的 gpg 密钥并将它放在我的 Windows 机器上的 C:/Users/Sara/AppData/Roaming/gnupg 文件夹下。从另一个问题Where to keep a GPG secret key for a Maven project in CI environment?,我可以看到答案是基于 Unix 的环境。任何人都可以阐明在 windows 环境中将 jenkins 的密钥放在哪里?

[INFO] --- maven-gpg-plugin:1.1:sign (sign-artifacts) @ StudentEnrollmentWithREST ---
    gpg: no default secret key: secret key not available
    gpg: signing failed: secret key not available
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1:27.647s
    [INFO] Finished at: Mon Jan 20 12:12:27 CST 2014
    [INFO] Final Memory: 22M/53M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.1:sign (sign-artifacts) on project StudentEnrollmentWithREST: Exit code: 2 -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:45.118s
[INFO] Finished at: Mon Jan 20 12:12:33 CST 2014
[INFO] Final Memory: 8M/19M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.1:prepare (default-cli) on project StudentEnrollmentWithREST: Maven execution failed, exit code: '1' -> [Help 1]
[JENKINS] Archiving C:\Program Files (x86)\Jenkins\workspace\Upload REST Release Artifacts\pom.xml to com.github.elizabetht/StudentEnrollmentWithREST/1.3-SNAPSHOT/StudentEnrollmentWithREST-1.3-SNAPSHOT.pom
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
channel stopped
Skipping Cobertura coverage report as build was not UNSTABLE or better ...
Finished: FAILURE

【问题讨论】:

    标签: maven jenkins


    【解决方案1】:

    根据gpg:sign 文档。
    默认为~/.gnupg%APPDATA%/gnupg${gpg.homedir} 应该在您当前描述的文件夹中找到您的密钥环。 也可以配置默认名为pubring.gpgsecring.gpg的文件。

    也许问题在于找到正确的密钥,除非另有配置,否则 maven 使用“默认密钥”。 密钥环中的第一个密钥是默认密钥。

    选择一个键 - 这可能在项目/父级或设置中,甚至在命令行中

    <properties>
        <gpg.keyname>C78F3CC4</gpg.keyname>
    </properties>
    

    其他一些配置更有可能是“每个主机”,可能是您的 settings.xml 中的配置文件

    <profile>
        <id>gpg-release</id>
        <properties>
            <gpg.passphrase>...</gpg.passphrase>
            <gpg.useagent>true</gpg.useagent>
    <!--
            <gpg.defaultKeyring>false</gpg.defaultKeyring>
            <gpg.homedir>/private/.../.gnupg</gpg.homedir>
            <gpg.publicKeyring>/private/.../.gnupg/pubring.gpg</gpg.publicKeyring>
            <gpg.secretKeyring>/private/.../.gnupg/secring.gpg</gpg.secretKeyring>
    -->
        </properties>
    </profile>
    

    如果您在 OSS Sonatype 中使用命令行而不是在您的设置 xml 中,则需要进一步的操作。
    来自OSS Sonatype documentation.
    因为 maven-release-plugin 将启动一个新的 Maven 实例,-Dgpg.passphrase=PASSPHRASE 在这种情况下将不起作用,相反,您应该使用 mvn release:perform -Darguments=-Dgpg.passphrase=PASSPHRASE [并在项目pom中配置${arguments}的用法]

    【讨论】:

      【解决方案2】:

      在 settings.xml 中添加配置文件部分,如下所示

      <profile> 
      <id>gpg-release</id> 
      <properties> 
      <gpg.passphrase>password</gpg.passphrase> 
      <gpg.useagent>true</gpg.useagent> 
      <gpg.defaultKeyring>false</gpg.defaultKeyring> <gpg.homedir>C:/Users/User/AppData/Roaming/gnupg</gpg.homedir> <gpg.publicKeyring>C:/Users/User/AppData/Roaming/gnupg/pubring.gpg</gpg.publicKe‌​yring> <gpg.secretKeyring>C:/Users/User/AppData/Roaming/gnupg/secring.gpg</gpg.secre‌​tKeyring> </properties> 
      </profile>
      

      【讨论】:

        【解决方案3】:

        您可以将 GPG 密钥保存在 Jenkins 的管理 Jenkins/configure-system 中。有一个 RPM 签名密钥部分,您可以在其中添加 GPG 密钥。在您应该在 Jenkins 中添加所需的插件之前

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-11-22
          • 1970-01-01
          • 2013-12-12
          • 2010-11-24
          • 2017-07-07
          • 2011-04-30
          • 1970-01-01
          相关资源
          最近更新 更多