1

我們正試圖讓M2 Release Plugin將發佈的工件部署到我們的Artifactory服務器。在我們pom.xml的配置看起來像這樣爲什麼Jenkins上的M2 Release Plugin沒有通過Artifactory驗證?

.... 
<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> 

如果我們現在就詹金斯開始發佈版本,Maven的告訴我們,它收到來自Artifactory的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」i試圖對這個URL做一個HTTP PUT請求。

在Maven或Jenkins中是否存在一些我們錯過的配置?憑據是正確的,如果我在我的本地機器上使用Jenkins的settings.xml,一切都按預期工作。

+0

看起來Jenkins沒有拿起您提供的設置文件。不知道爲什麼,以及一些不相關的話題,爲什麼不使用[Artifactory Jenkins插件](https://wiki.jenkins-ci.org/display/JENKINS/Artifactory+Plugin)?它完全解決了這個問題,並具有內置的發佈功能。 – JBaruch

+0

這就是我們想的,也許是插件中的一個錯誤,但我想確保我們不會錯過任何東西。 我們使用這個插件,但僅用於SNAPSHOT構建的自動部署。我們發現這個插件的發佈管理缺乏Jenkins M2發佈插件的一些功能(例如,單獨向SCM寫入憑據,區分發布版本/非發佈buids,...) – moxn

+1

您可以完全自定義發佈的邏輯通過使用[staging用戶插件](http://www.jfrog.com/confluence/display/RTF/User+Plugins#UserPlugins-Staging)。一些例子在[我們的GitHub](https://github.com/JFrogDev/artifactory-user-plugins) – JBaruch

回答

1

在2.2.2之前有a bug in the Maven release plugin,這使得它忽略配置文件提供程序傳遞給Maven的設置文件。解決的辦法是在您的項目pom.xml中指定一個更新的maven release插件,如下所示:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-release-plugin</artifactId> 
      <version>2.4.2</version> 
     </plugin> 
    </plugins> 
</build> 
+0

感謝您的回覆,但我們當時正在使用2.3.2。 – moxn

+0

Doh,現在在您的問題中看到了版本號!除此之外,你的問題的描述與我的完全一樣,所以我想我會留下我的回答,以防別人幫助別人。 – robpvn

+0

Upvoting這個答案,因爲它在一個相關但略有不同的上下文中爲我們解決了一個問題。在另一個模塊中,我們沒有爲這個插件設置版本,所以Maven使用了2.7.x.切換回2.4.1解決了這個問題。 – moxn

相關問題