Jenkinsでビルド~Archivaにリポジトリ登録

Jenkinsビルド後のmvn deployで、Archivaリポジトリに登録する際にエラーが発生。

------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error deploying artifact: Failed to transfer file: http://mydomain/archiva/repository/xxx/common.pom. Return code is: 401 Unauthorized

やったこと。

  • Archivaリポジトリ作成、ユーザ作成、アップロード権限付与
  • pom.xmlの設定(下記、 Deploying to Repository参照)
  • settings.xmlの設定(←これが間違っていた。$MAVEN_HOME/conf/settings.xmlの方をいじっていた。。)
  • Jenkinsのジョブ実行。デプロイ時にエラー。

対応:Jenkins起動ユーザ(jenkins)の$JENKINS_HOME/.m2/settings.xmlを作成して、正しい認証情報を記述

参考:http://archiva.apache.org/docs/1.0.1/userguide/deploy.html

Deploying to Repository

Configuring Maven to deploy to an Archiva repository

  1. Create a user in Archiva to use for deployment
  2. The deployment user needs the Role 'Repository Manager' for each repository that you want to deploy to
  3. Define the server for deployment inside your 'settings.xml', use the newly created user for authentication
      <settings>
        ...
        <servers>
          <server>
            <id>deployment.webdav</id>
            <username>{archiva-deployment-user}</username>
            <password>{archiva-deployment-pwd}</password>
          </server>
          ...
        </servers>
        ...
      </settings>

Deploying to Archiva using WebDAV

  1. Configure the distributionManagement part of your pom.xml (customising the URLs as needed)
      <project>
        ...
        <distributionManagement>
          <repository>
            <id>archiva.internal</id>
            <name>Internal Release Repository</name>
            <url>dav:http://reposerver.mycompany.com:8080/archiva/repository/internal/</url>
          </repository>
          <snapshotRepository>
            <id>archiva.snapshots</id>
            <name>Internal Snapshot Repository</name>
            <url>dav:http://reposerver.mycompany.com:8080/archiva/repository/snapshots/</url>
          </snapshotRepository>
        </distributionManagement>
        ...
      </project>
  2. Add a build extension to your pom.xml
      <project>
        ...
        <build>
          <extensions>
            <extension>
              <groupId>org.apache.maven.wagon</groupId>
              <artifactId>wagon-webdav</artifactId>
              <version>1.0-beta-2</version>
            </extension>
          </extensions>
        </build>
        ...
      </project>
  3. Finally the user that is running archiva (tomcat-user, plexus-user,..) must have write access to the deployment repository.

参考:http://www.seasar.org/wiki/index.php?Maven2DeployToRepoRemoteWithWebDAV#n5b91412