【发布时间】:2020-06-03 19:24:48
【问题描述】:
我有一个 Maven 项目,想使用 mvn clean deploy 构建它,以便将构建的工件部署到 Nexus 存储库中。
该存储库的访问数据(用户名和密码)存储在 Jenkins 凭据中。
我想在 Jenkins 中调用 mvn deploy,以便从 Jenkins 中读取该 Nexus 存储库的凭据(未在 settings.xml 中硬编码)。
如果我无法访问 Jenkins 服务器上的settings.xml,我该怎么办?
更新 1:
我在“配置文件管理”(JENKINS_URL/configfiles/index) 中创建了一个条目,其中包含以下数据:
输入:Maven settings.xml
全部替换:是
服务器 ID:myServer
凭据:Credentials for the Nexus repository
内容:
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>myServer</id>
<username>foo</username>
<password>bar</password>
</server>
</servers>
</settings>
myServer也用在我要构建的工件的pom.xml中:
<distributionManagement>
<repository>
<id>myServer</id>
<url>http://nexus.mycompany.com</url>
</repository>
</distributionManagement>
在作业的配置中,我包含了如下所示的那些设置。 Nexus settings.xml是“配置文件管理”中的配置。
但它不起作用——当构建尝试将工件部署到 Nexus 时,我收到“禁止”错误。
更新 2:当我使用与 Jenkins 中相同的凭据(存储在我的本地 settings.xml)在本地运行 mvn -X deploy 时,我看到以下输出:
[DEBUG] Failed to decrypt password for server XXX release repository: org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: java.io.FileNotFoundException: /XXXXXXXXXXXXXXX/.m2/settings-security.xml (No such file or directory)
org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: java.io.FileNotFoundException: /XXXXXXXXXXXXXXX/.m2/settings-security.xml (No such file or directory)
at org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher.decrypt(DefaultSecDispatcher.java:121)
at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt(DefaultSettingsDecrypter.java:107)
at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt(DefaultSettingsDecrypter.java:63)
at org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory.newRepositorySession(DefaultRepositorySystemSessionFactory.java:165)
但是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">
<localRepository/>
<interactiveMode/>
<offline/>
<pluginGroups/>
<servers>
<server>
<id>NEXUS_REPOSITORY_SNAPSHOTS</id>
<username>user</username>
<password>password</password>
</server>
</servers>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>
我发现了一个关于类似错误的报告here。
【问题讨论】:
-
您想在 pom.xml 中使用存储库的凭据吗?如果是这种情况,您可以查看stackoverflow.com/questions/14333577/…
-
@Sambit 不,我不知道。凭据存储在 Jenkins 中。 Jenkins配置页面有一个菜单项“Credentials”。
标签: java maven jenkins maven-3