我们正试图让M2 Release Plugin将已发布的工件部署到我们的Artifactory服务器。我们pom.xml
中的配置如下所示
....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
....
<distributionManagement>
<repository>
<id>artifactory</id>
<url>http://example.com/artifactory/jenkins-release</url>
</repository>
</distributionManagement>
使用Config File Provide Plugin我们指定了具有正确凭据的全局settings.xml
<settings>
<servers>
<server>
<id>artifactory</id>
<username>jenkins</username>
<password>secret!</password>
</server>
</servers>
</settings>
如果我们现在开始在Jenkins上发布版本,Maven告诉我们它收到了来自神器的HTTP 401
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project example-maven-plugin: Failed to deploy artifacts: Could not transfer artifact com.example.maven.plugins:example-maven-plugin:jar:0.0.9 from/to artifactory (http://example.com/artifactory/jenkins-release): Failed to transfer file: http://example.com/artifactory/jenkins-release/com/example/maven/plugins/example-maven-plugin/0.0.9/example-maven-plugin-0.0.9.jar. Return code is: 401, ReasonPhrase:Unauthorized. -> [Help 1]
在服务器日志中,我们看到用户“non_authenticated_user”正在尝试对此URL执行HTTP PUT请求。
我们缺少Maven或Jenkins的配置吗?凭证是正确的,如果我在本地机器上使用Jenkins的settings.xml,一切都按预期工作。
答案 0 :(得分:1)
2.2.2之前有a bug in the Maven release plugin,它忽略了Config File Provider传递给Maven的设置文件。解决方案是在项目pom.xml中指定一个更新的maven发布插件,如下所示:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
</plugin>
</plugins>
</build>