Password protected jenkins maven repository server - access from maven

放肆的年华 提交于 2020-01-03 03:16:09

问题


I've got a password protected jenkins server with the Jenkins Maven Repository Server plugin. My problem is, as it is password protected, i can't access the /plugin/repository/everything/ repo from within maven (Could not transfer metadata <metadata> from/to <repo-name> (http://ci.mydomain.com/plugin/repository/everything/): Access denied to: <repo>/<identifier> , ReasonPhrase:Forbidden.)

What i tried:
- Putting the server credentials in the .m2/settings.xml
- Basic auth: http://<user>:<password>@ci.mydomain.com/<repo>
- without any auth

none worked...

any help would be appreciated.

EDIT:

My settings.xml:

<settings>
  <servers>
      <server>
        <id>test-ci</id>
        <username>jenkins</username>
        <password>password</password>
    </server>
  </servers>
</settings>

and my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project>

    <groupId>com.mygroup</groupId>
    <artifactId>Artifact</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <repositories>
        <repository>
            <id>test-ci</id>
            <url>http://ci.mydomain.com/plugin/repository/everything/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.mygroup</groupId>
            <artifactId>ProjectOnCi</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

</project>

回答1:


Just struggled a few hours with this problem today and finally found an answer.

First of all, to use HTTP basic authentication, you need to supply user and API Token as password. You can find this token at "Manage Jenkins" -> "Manage Users" -> "Edit User" (Settings icon next to user) -> "Show API Token".

Secondly, Jenkins is using preemptive authentication, which means that there is no HTTP authentication negotiation but you need to immediately send the credentials in the first request. You can read about it here: https://wiki.jenkins.io/display/JENKINS/Authenticating+scripted+clients

To configure your Maven repository accordingly, make sure to use the following server configuration:

<server>
    <id>test-ci</id>
    <username>YOUR_USER</username>
    <password>YOUR_API_TOKEN</password>
    <configuration>
        <httpConfiguration>
            <all>
                <usePreemptive>true</usePreemptive>
            </all>
        </httpConfiguration>
    </configuration>
</server>

This should work. I hope I could help you :)




回答2:


You should note that Jenkins Maven Repository Server will not perform as Maven Repository, so if this is what you need (a Maven repo) - this Jenkins plugin will not help.

I suggest reading about Maven Repos; from what you write I think that an internal repository (e.g. Nexus, Artifactory) might be good. Maven by default downloads JARs from Maven Central, so you do not (and should not) have to download all sources and build them.



来源:https://stackoverflow.com/questions/35733227/password-protected-jenkins-maven-repository-server-access-from-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!