我收到错误消息“返回代码是:401,ReasonPhrase:未经授权。” 尝试通过 jenkins 将工件部署到 nexus 时

Akl*_*aik 2 nexus maven jenkins

我在“u01/jenkins/.m2/”中有我的 settings.xml 文件。这是我必须为 nexus 部署配置的地方吗?请指教

[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.
Run Code Online (Sandbox Code Playgroud)

car*_*ing 6

您的文件中需要有一个<distributionManagement/>部分pom.xml。像这样的东西:

<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>
Run Code Online (Sandbox Code Playgroud)

然后你还需要在你的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>
Run Code Online (Sandbox Code Playgroud)

请注意,<id/>在你的部分<distributionManagement/>pom.xml应该与那些在您的<server/>部分在settings.xml文件中。

此外,您的settings.xml文件必须(通常)位于 下~/.m2,除非您已在 Jenkins 中定义了这些文件。