2017-09-05 1 views
0

私のsettings.xmlファイルは 'u01/jenkins/.m2 /'にあります。これは、Nexusの導入のために設定する必要がある場所ですか? (すべてのユーザーに対してグローバルに使用できる)のMavenがインストールされているフォルダまたは$HOME/.m2/settings.xmlでジェンキンスジョブを実行しているユーザーのホームフォルダのいずれかで行くべき「リターンコードは、401、ReasonPhrase:Unauthorized」というエラーが表示されます。ゲンキンを通して成果物をネクサスにデプロイしようとしたとき

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project jenktest: Failed to deploy artifacts: Could not transfer artifact tulsa.jenkins.test:jenktest:pom:0.0.1-20170905.090435-1 from/to snapshots (http://myhost:8081/nexus/content/repositories/snapshots): Failed to transfer file: http://myhost:8081/nexus/content/repositories/snapshots/tulsa/jenkins/test/jenktest/0.0.1-SNAPSHOT/jenktest-0.0.1-20170905.090435-1.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project jenktest: Failed to deploy artifacts: Could not transfer artifact tulsa.jenkins.test:jenktest:pom:0.0.1-20170905.090435-1 from/to snapshots (http://204.26.165.206:8081/nexus/content/repositories/snapshots): Failed to transfer file: http://myhost:8081/nexus/content/repositories/snapshots/tulsa/jenkins/test/jenktest/0.0.1-SNAPSHOT/jenktest-0.0.1-20170905.090435-1.pom. Return code is: 401, ReasonPhrase: Unauthorized. 

答えて

0

あなたのMavenの設定ファイルをアドバイスしてください。

mvn -X | grep settingsに電話して、Mavenが設定ファイルを探している場所を確認できます。

+0

私はジェンキンスジョブフォルダ内のsettings.xmlファイルを参照してくださいと私は不正アクセスエラーが直面しているイムthogh、展開権限を持つリポジトリとユーザーとのsettings.xmlファイルを構成したのですか?考えられる理由は何ですか?ありがとう –

+0

settings.xmlは、あなたのjenkinsジョブフォルダに置くべきではありません。 '/ home/[JENKINS_USERNAME] /。m2/settings.xml'になければなりません。 –

1

pom.xmlファイルに<distributionManagement/>セクションが必要です。このような何か:

<distributionManagement> 
    <repository> 
     <id>my-releases</id> 
     <name>my-releases</name> 
     <url>http://your-repository-host:8081/nexus/content/repositories/my-releases/</url> 
     <layout>default</layout> 
    </repository> 
    <snapshotRepository> 
     <id>my-snapshots</id> 
     <name>my-snapshots</name> 
     <url>http://your-repository-host:8081/nexus/content/repositories/my-snapshots/</url> 
     <layout>default</layout> 
    </snapshotRepository> 
</distributionManagement> 

次に、あなたもあなたのsettings.xmlファイル内でこのような何かを持っている必要があります:

<servers> 
    <server> 
     <id>my-releases</id> 
     <username>your-username</username> 
     <password>your-password</password> 
    </server> 
    <server> 
     <id>my-snapshots</id> 
     <username>your-username</username> 
     <password>your-password</password> 
    </server> 
</servers> 

してください、あなたのpom.xmlであなたの<distributionManagement/>でのセクションでは、あなたのものと一致する必要がありませんということsettings.xmlファイルの<server/>セクション。

また、settings.xmlファイルは、ジェンキンスでファイルを定義していない限り、~/.m2に(通常)存在する必要があります。

0

スレーブから手動でデプロイを実行しようとしている場合は、正しいsettings.xmlを使用していることを確認してください。-xをmvnコマンドに追加してください。

1

私は同じような状況で解決しました。 「リリース」ジョブ中に「401 unauthorized」を取得していました。それが私たちの一般的な設定に自信を与えたので、/、働いていた「展開」

"clean release:clean release:prepare release:perform" 

"clean deploy". 

へ:それをデバッグしようとしますが

は、我々はからジェンキンス/ Mavenのジョブを変更しました仕事の配管面。しかし、 "リリース"はまだ失敗していた。 (私たちはインライン目標とオプションを変更したので)ジョブ構成の他のすべての側面は、我々の場合には、我々はsettings.xmlファイルに資格情報をハードコーディングいけない、それはより複雑にするために

enter image description here

同一でした。むしろ、それらはビルド/ジョブ時にJenkinsによって注入されます。

ここに「NEXUS_USER」を追加します。 enter image description here

ここに「NEXUS_PASS」を追加します。 enter image description here

設定ジェンキンス/ Mavenを enter image description here

あなたのsettings.xmlファイルを使用するようにPOMにこれを追加します。settings.xmlからXML(ここでは驚きべきではない)

<distributionManagement> 
    <repository> 
     <id>com.xxx.repo_releases</id> 
     <url>https://sonatype-nexus.xxx.com/releases/</url> 
     <name>Internal releases repository</name> 
    </repository> 
    <snapshotRepository> 
     <id>com.xxx.repo_snapshots</id> 
     <url>https://sonatype-nexus.xxx.com/snapshots/</url> 
     <name>Internal snapshots repository</name> 
    </snapshotRepository> 
</distributionManagement> 

(このファイルは、当社のgitリポジトリ内のpom.xmlにピアである)

<servers> 
    <server> 
    <id>com.xxx.repo_releases</id> 
    <username>${env.NEXUS_USER}</username> 
    <password>${env.NEXUS_PASS}</password> 
    </server> 
    <server> 
    <id>com.xxx.repo_snapshots</id> 
    <username>${env.NEXUS_USER}</username> 
    <password>${env.NEXUS_PASS}</password> 
    </server> 
</servers> 

SOLUTION:それは問題が判明"maven-release-plugin"を使用していて、settings.xmlファイルの$ {NEXUS_USER}を補間できませんでした。我々が2.1から2.5.3にバージョンアップしたら、それはすべて機能しました。

enter image description here

関連する問題