maven - 尝试通过 jenkins 将 Artifact 部署到 nexus 时出现错误 "Return code is: 401, ReasonPhrase: Unauthorized."

标签 maven jenkins nexus

我的 settings.xml 文件位于“u01/jenkins/.m2/”中。这是我必须为 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.

最佳答案

您需要有一个 <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>

那么你的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>

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

另外,您的settings.xml文件必须(通常)位于 ~/.m2 下, 除非你已经在 J​​enkins 中定义了。

关于maven - 尝试通过 jenkins 将 Artifact 部署到 nexus 时出现错误 "Return code is: 401, ReasonPhrase: Unauthorized.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46053199/

相关文章:

git - 为什么 bitbucket 分支项目会 checkout 两次?

maven - 使用 Sonatype Nexus OSS 进行基于功能的开发

maven - 尽管Maven在路径上,但无法运行程序 “mvn”

java - 如何创建模块化的java项目?

java - GWT + Maven + Eclipse -> 简单的方法?

maven - Jsch 和 Maven 有什么问题?

jenkins - 删除具有匹配模式的 Jenkins 作业

docker - 设置docker-compose环境变量以使用自定义java System.Property正确启动Jenkins

java - 搜索 Nexus 永远不会显示最新的 Artifact 版本

ansible - 如何使用ansible playbook在 "nexus local user and role"中创建 "sonatype nexus"