首页 文章

推荐的构建插件将工件部署到存储库

提问于
浏览
5

我们有一个在Windows奴隶上运行的Jenkins Maven构建,它在每次提交时运行maven包 . 我正在尝试使用提升的构建插件将提升的构建部署到nexus发布存储库 .

我已将"promote build when..."设置为手动批准,并将操作设置为"Deploy artifact to Maven Repository"将存储库URL设置为“http://example.com:8081/nexus/content/repositories/releases/ " and the repo id to " release” . 但是,当批准被触发时,我们得到以下堆栈跟踪:

[INFO]部署在http://example.com:8081/nexus/content/repositories/releases/(id = release,uniqueVersion = true)部署主要工件artifactid-1.0.2.pom上传:http:// example.com:8081/nexus/content/repositories/releases/groupid/artifactid/1.0.2/artifactid-1.0.2.pom错误:无法部署工件:无法传输工件groupid:artifactid:pom:1.0.2 from /发布(http://example.com:8081/nexus/content/repositories/releases/):无法传输文件:http://example.com:8081 /nexus / content / deposits / release / groupid / artifactid /1.0.2/artifactid-1.0.2.pom . 返回码为:401,ReasonPhrase:未经授权 . org.apache.maven.artifact.deployer.ArtifactDeploymentException:无法部署工件:无法传输工件groupid:artifactid:pom:1.0.2 from / to release(http://example.com:8081/nexus/content/repositories / releases /):无法传输文件:http://example.com:8081 /nexus / content / deposits / release / groupid / artifactid / 1.0.2 /artifactid-1.0.2.pom . 返回码为:401,ReasonPhrase:未经授权 . at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:143)at hudson.maven.reporters.MavenArtifactRecord.deploy(MavenArtifactRecord.java:193)at hudson.maven.RedeployPublisher.perform(RedeployPublisher.java) :176)at hudson.plugins.promoted_builds.Promotion $ RunnerImpl.build(Promotion.java:282)at hudson.plugins.promoted_builds.Promotion $ RunnerImpl.doRun(Promotion.java:224)at hudson.model.AbstractBuild $ AbstractBuildExecution . 在hudson.model.Run.run(Run.java:1678)的hudson.model.Run.exe(Run.java:1640)运行(AbstractBuild.java:533)hudson.plugins.promoted_builds.Promotion.run(推广) .java:174)at hudson.model.ResourceController.execute(ResourceController.java:89)at hudson.model.Executor.run(Executor.java:240)

如果我将促销操作更改为触发maven部署,则重新运行构建并且部署目标按预期工作,如果我添加git发布者,则在身份验证时也会失败 . 如果运行Jenkins的用户在本地执行,则两个操作都会成功 .

升级的构建插件如何确定部署的身份验证详细信息?

1 回答

  • 0

    要执行需要使用Maven进行身份验证的部署,您需要在settings.xml file中配置具有正确信息的服务器 . 因此,使用以下内容修改(或创建)您的用户设置(在 ${user.home}/.m2/settings.xml 下):

    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
      ...
      <servers>
        <server>
          <id>releases</id>
          <username>my_login</username>
          <password>my_password</password>
        </server>
      </servers>
      ...
    </settings>
    

    这将使用给定的用户名和密码定义名为 releases 的服务器配置 . 如果需要,您可以使用密码或私钥 .

    然后,您需要确保Jenkins正确读取您的Maven设置文件 . 在Jenkins 2.8下,您可以导航到“Jenkins>全局工具配置” .

    enter image description here

    这两个选项指向之前修改过的全局Maven设置和用户设置 .

    最后,您需要确保Jenkins中配置的构建操作正在查找已配置的服务器 . 在"Deploy artifacts to Maven repository"操作中,编写部署URL,"Repository ID"应该是 settings.xml 中配置的服务器的 <id> ,在这种情况下为 releases

    enter image description here

相关问题