gpt4 book ai didi

maven - 提升构建插件将 Artifact 部署到存储库

转载 作者:行者123 更新时间:2023-12-03 17:48:39 27 4
gpt4 key购买 nike

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

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

[INFO] Deployment in http://example.com:8081/nexus/content/repositories/releases/ (id=release,uniqueVersion=true) Deploying the main artifact artifactid-1.0.2.pom Uploading: http://example.com:8081/nexus/content/repositories/releases/groupid/artifactid/1.0.2/artifactid-1.0.2.pom ERROR: Failed to deploy artifacts: Could not transfer artifact groupid:artifactid:pom:1.0.2 from/to release (http://example.com:8081/nexus/content/repositories/releases/): Failed to transfer file: http://example.com:8081/nexus/content/repositories/releases/groupid/artifactid/1.0.2/artifactid-1.0.2.pom. Return code is: 401, ReasonPhrase: Unauthorized. org.apache.maven.artifact.deployer.ArtifactDeploymentException: Failed to deploy artifacts: Could not transfer artifact groupid:artifactid:pom:1.0.2 from/to release (http://example.com:8081/nexus/content/repositories/releases/): Failed to transfer file: http://example.com:8081/nexus/content/repositories/releases/groupid/artifactid/1.0.2/artifactid-1.0.2.pom. Return code is: 401, ReasonPhrase: Unauthorized. 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.run(AbstractBuild.java:533) at hudson.model.Run.execute(Run.java:1740) at hudson.model.Run.run(Run.java:1678) at hudson.plugins.promoted_builds.Promotion.run(Promotion.java:174) at hudson.model.ResourceController.execute(ResourceController.java:89) at hudson.model.Executor.run(Executor.java:240)



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

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

最佳答案

要执行需要使用 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 中配置的构建操作正在查找配置的服务器。在您的“将 Artifact 部署到 Maven 存储库”操作中,写入您的部署 URL,“存储库 ID”应为 <id>settings.xml 中配置的服务器, 即 releases在这种情况下:

enter image description here

关于maven - 提升构建插件将 Artifact 部署到存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26906566/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com