我收到错误“返回代码是:401,ReasonPhrase:未经授权。”当试图通过jenkins部署工件到nexus
我在'u01/jenkins/.m2 /'中有我的settings.xml文件。这是我必须配置nexus部署的地方吗?请指点我收到错误“返回代码是:401,ReasonPhrase:未经授权。”当试图通过jenkins部署工件到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.
你的Maven设置文件应该去无论是在(全球适用于所有用户)Maven的安装在文件夹或正在执行中$HOME/.m2/settings.xml
詹金斯的作业,用户的主文件夹。
您可以拨打mvn -X | grep settings
来查看Maven在哪里查找设置文件。
您需要在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>
请,不就是部分在<distributionManagement/>
在pom.xml
应该匹配在您的<server/>
部分在您的settings.xml
文件中。
此外,您的settings.xml
文件必须(通常)位于~/.m2
之下,除非您已在Jenkins中定义了它们。
尝试从从站手动运行部署,如果可行,请确保使用正确的settings.xml,将-x
添加到您的mvn命令中。
我有类似的情况,我们解决了;在“发布”工作期间,我们遇到了“401未经授权”的情况。
虽然试图调试它,我们从改变詹金斯/ Maven的工作:
"clean release:clean release:prepare release:perform"
到
"clean deploy".
的“部署”的工作,所以这给了我们在一般配置的信心/管道工作的方面。但“释放”仍然失败;任务配置中的所有其他方面是相同的(因为我们只是直列改变目标和选项)
为了使问题更加复杂,在我们的情况下,我们不Settings.xml文件中硬编码的凭据。相反,这些是Jenkins在构建/作业时注入的。
配置詹金斯/ Maven来使用你的settings.xml文件
添加到您的POM。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>
从settings.xml文件(该文件是一个对等方的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,一切都奏效了。
我看到了詹金斯的工作文件夹中的settings.xml文件,我并配置有具有部署特权回购和用户的settings.xml文件,thogh面临着未经授权的访问错误的IM?可能的原因是什么?谢谢 –
settings.xml不应该在你的jenkins作业文件夹中。它应该在'/ home/[JENKINS_USERNAME] /。m2/settings.xml'中。 –