如何通过 Jenkins Build Offline 将工件部署到 Maven Repository (JFrog artifactory)?
How to deploy artifacts to Maven Repository (JFrog artifactory) through Jenkins Build Offline?
上下文:
我正在尝试通过安装在离线环境(无互联网连接)中的 Jenkins 在 Maven 项目上进行简单构建(不是通过管道作业)。构建成功,我看到 HelloMaven.jar 成功部署到再次离线安装的 JFrog artifactory。
问题:
但是整个 Jenkins 构建失败的原因是
"Build Step:Deploy artifacts to Maven Repository changed build result to FAILURE"
Jenkins 构建控制台输出如下:
Started by user admin
Building in workspace C:\Users\dipakrai\.jenkins\workspace\HelloMaven
Updating https://myownlaptop/svn/HelloMavenDemo/HelloMaven at revision '2017-07-13T11:51:44.844 +0530'
Using sole credentials admin/****** (SVN) in realm <https://myownlaptop.com:443> VisualSVN Server
At revision 6
No changes for https://myownlaptop.com/svn/HelloMavenDemo/HelloMaven since the previous build
Parsing POMs
Established TCP socket on 62532
[HelloMaven] $ "C:\Program Files\Java\jdk1.8.0_65/bin/java" -cp "C:\Users\dipakrai\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-agent-1.11.jar;C:\Program Files\Apache Software Foundation\apache-maven-3.0.3\boot\plexus-classworlds-2.4.jar" org.jvnet.hudson.maven3.agent.Maven3Main "C:\Program Files\Apache Software Foundation\apache-maven-3.0.3" C:\Users\dipakrai\.jenkins\war\WEB-INF\lib\remoting-3.7.jar C:\Users\dipakrai\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-1.11.jar C:\Users\dipakrai\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.11.jar 62532
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven: -B -f C:\Users\dipakrai\.jenkins\workspace\HelloMaven\pom.xml deploy
[INFO] Scanning for projects...
[HUDSON] Collecting dependencies info
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloMaven 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- buildnumber-maven-plugin:1.3:create (default) @ HelloMaven ---
[INFO] Executing: cmd.exe /X /C "svn --non-interactive info"
[INFO] Working directory: C:\Users\dipakrai\.jenkins\workspace\HelloMaven
[INFO] Storing buildNumber: null at timestamp: 1499926911471
[INFO] Executing: cmd.exe /X /C "svn --non-interactive info"
[INFO] Working directory: C:\Users\dipakrai\.jenkins\workspace\HelloMaven
[INFO] Storing buildScmBranch: UNKNOWN_BRANCH
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ HelloMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ HelloMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ HelloMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\dipakrai\.jenkins\workspace\HelloMaven\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ HelloMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ HelloMaven ---
[INFO] No tests to run.
[INFO] Surefire report directory: C:\Users\dipakrai\.jenkins\workspace\HelloMaven\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[JENKINS] Recording test results
[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ HelloMaven ---
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ HelloMaven ---
[INFO] Installing C:\Users\dipakrai\.jenkins\workspace\HelloMaven\target\HelloMaven.jar to C:\Users\dipakrai\.m2\repository\net\roseindia\maven\quickstart\HelloMaven.0-SNAPSHOT\HelloMaven-1.0-SNAPSHOT.jar
[INFO] Installing C:\Users\dipakrai\.jenkins\workspace\HelloMaven\pom.xml to C:\Users\dipakrai\.m2\repository\net\roseindia\maven\quickstart\HelloMaven.0-SNAPSHOT\HelloMaven-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ HelloMaven ---
Downloading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar (4 KB at 18.4 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.pom
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.pom (4 KB at 8.6 KB/sec)
Downloading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml (784 B at 16.3 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml (298 B at 1.5 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.064s
[INFO] Finished at: Thu Jul 13 11:51:55 IST 2017
[INFO] Final Memory: 15M/247M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving C:\Users\dipakrai\.jenkins\workspace\HelloMaven\pom.xml to net.roseindia.maven.quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-SNAPSHOT.pom
[JENKINS] Archiving C:\Users\dipakrai\.jenkins\workspace\HelloMaven\target\HelloMaven.jar to net.roseindia.maven.quickstart/HelloMaven/1.0-20170713.062154-1/HelloMaven-1.0-20170713.062154-1.jar
Used promoter class: org.jenkinsci.plugins.artifactpromotion.NexusOSSPromotor
channel stopped
Local repository path: [C:\Users\dipakrai\.jenkins\workspace\HelloMaven\target\local-repo]
Started with promotion
Get Artifact and corresponding POM
Checking if POM already exists in releaserepo
POM doesn't exist in release repo, it will be deployed
Downloading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml
##################################################]
Downloaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml ( at 31.9 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.055434-15.jar
##################################################]
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.055434-15.jar ( at 17.5 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.055434-15.pom
##################################################]
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.055434-15.pom ( at 9.3 KB/sec)
Downloading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml
##################################################]
Downloaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml ( at 7.3 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml
##################################################]
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml ( at 10.5 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml
##################################################]
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml ( at 2.1 KB/sec)
Skipping deletion of artifact from source repo as requested by user
Maven RedeployPublisher use remote maven settings from : C:\Users\dipakrai/.m2/settings.xml
[INFO] Deployment in http://localhost:8081/artifactory/repo1 (id=ArtifactID,uniqueVersion=true)
Deploying the main artifact HelloMaven-1.0-20170713.062154-1.jar
Downloading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml
Downloaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml (787 B at 1.9 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.pom
ERROR: Failed to deploy artifacts: Could not transfer artifact net.roseindia.maven.quickstart:HelloMaven:jar:1.0-20170713.062154-1 from/to ArtifactID (http://localhost:8081/artifactory/repo1): Failed to transfer file: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar. Return code is: 401, ReasonPhrase: Unauthorized.
org.apache.maven.artifact.deployer.ArtifactDeploymentException: Failed to deploy artifacts: Could not transfer artifact net.roseindia.maven.quickstart:HelloMaven:jar:1.0-20170713.062154-1 from/to ArtifactID (http://localhost:8081/artifactory/repo1): Failed to transfer file: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar. Return code is: 401, ReasonPhrase: Unauthorized.
at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:143)
at hudson.maven.reporters.MavenArtifactRecord.deploy(MavenArtifactRecord.java:193)
at hudson.maven.RedeployPublisher.perform(RedeployPublisher.java:176)
at hudson.tasks.BuildStepMonitor.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:735)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:676)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1072)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:621)
at hudson.model.Run.execute(Run.java:1760)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:542)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:405)
Caused by: org.eclipse.aether.deployment.DeploymentException: Failed to deploy artifacts: Could not transfer artifact net.roseindia.maven.quickstart:HelloMaven:jar:1.0-20170713.062154-1 from/to ArtifactID (http://localhost:8081/artifactory/repo1): Failed to transfer file: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar. Return code is: 401, ReasonPhrase: Unauthorized.
at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:317)
at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:245)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.deploy(DefaultRepositorySystem.java:420)
at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:139)
... 11 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact net.roseindia.maven.quickstart:HelloMaven:jar:1.0-20170713.062154-1 from/to ArtifactID (http://localhost:8081/artifactory/repo1): Failed to transfer file: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar. Return code is: 401, ReasonPhrase: Unauthorized.
at org.eclipse.aether.connector.basic.ArtifactTransportListener.transferFailed(ArtifactTransportListener.java:43)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:355)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector.put(BasicRepositoryConnector.java:274)
at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:311)
... 14 more
Caused by: org.apache.maven.wagon.TransferFailedException: Failed to transfer file: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar. Return code is: 401, ReasonPhrase: Unauthorized.
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:631)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:553)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:535)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:529)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:509)
at org.eclipse.aether.transport.wagon.WagonTransporter$PutTaskRunner.run(WagonTransporter.java:644)
at org.eclipse.aether.transport.wagon.WagonTransporter.execute(WagonTransporter.java:427)
at org.eclipse.aether.transport.wagon.WagonTransporter.put(WagonTransporter.java:410)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$PutTaskRunner.runTask(BasicRepositoryConnector.java:510)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:350)
... 16 more
[INFO] Deployment failed after 0.55 sec
Build step 'Deploy artifacts to Maven repository' changed build result to FAILURE
Finished: FAILURE
我的 HelloMaven 项目的 pom.xml 文件条目如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.roseindia.maven.quickstart</groupId>
<artifactId>HelloMaven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>HelloMaven</name>
<scm>
<connection>scm:svn:https://mylaptop/svn/myRepo/</connection>
</scm>
<build>
<finalName>HelloMaven</finalName>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<outputDirectory>${project.basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<archive>
<manifestEntries>
<SCM-Revision>${buildNumber}</SCM-Revision>
</manifestEntries>
</archive>
<webResources>
<resource>
<directory>${project.build.directory}/${project.build.finalName}</directory>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<targetPath>WEB-INF/classes</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>-->
<distributionManagement>
<repository>
<id>artifactory</id>
<name>HelloMaven-release</name>
<url>http://localhost:8081/artifactory/repo1</url>
</repository>
</distributionManagement>
</project>
MAVENm2文件夹的settings.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--<localRepository>C:\Users\dipakrai\.m2\repository</localRepository>-->
<pluginGroups>
<!-- Nothing is present now-->
</pluginGroups>
<proxies>
<!-- Nothing is present now-->
</proxies>
<servers>
<server>
<username>admin</username>
<password>{v2akWC7LO8QHuoPFXESAScpHLzTFzcIKG054oyvz/nc=}</password>
<id>central</id>
</server>
<server>
<username>admin</username>
<password>{v2akWC7LO8QHuoPFXESAScpHLzTFzcIKG054oyvz/nc=}</password>
<id>snapshots</id>
</server>
</servers>
<mirrors>
<mirror>
<id>artifactory</id>
<url>http://localhost:8081/artifactory/repo1</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>artifadeploymentRepoctory</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>HelloMaven-release</name>
<url>http://localhost:8081/artifactory/repo1</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>HelloMaven-snapshot</name>
<url>http://localhost:8081/artifactory/repo1</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
在过去的四天里,我一直在努力解决这个问题,并浏览了很多帖子 Infrastructure with maven, Jenkins, Nexus。我不确定我哪里出错了。
任何线索将不胜感激。
检查 mvn help:effective-settings
returns 以仔细检查您的 user/password 是否确实被使用了。
仔细检查 username/password 是否与 displayed here 匹配,其中 Atifactory 生成加密密码。
最后,在 this post 之后,避免将“central
”作为 ID。
@VonC 上面的回答帮助我解决了这个问题。我在 settings.xml
文件中输入的服务器 ID 与 Jenkins 人工制品配置不匹配。
我进行了以下更改,如下所列。
首先,我更新了我的 Jenkins 人工制品配置,如下所示。 存储库 ID 与 settings.xml 文件中提到的服务器 ID 完全匹配:
<server>
<username>admin</username>
<password>AP447H6DXXJW6WW54BvNBorau5s</password>
<id>artifactory</id>
</server>
并且 settings.xml
文件中下方的存储库 ID 条目必须与上面的服务器 ID 相同:
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>artifactory</id>
<name>myproject-release</name>
<url>http://localhost:8081/artifactory/repo2</url>
</repository>
其次,虽然我没有明确地测试过这个但它必须是这样的:
项目 pom.xml 文件中的 条目也应该与必须发布分发二进制文件的存储库具有相同的 ID(在这种情况下,人工制品)。
<distributionManagement>
<repository>
<id>artifactory</id>
<name>HelloMaven-release</name>
<url>http://localhost:8081/artifactory/repo1</url>
</repository>
</distributionManagement>
或者,因为您已经将 JFrog 工件与 Jenkins 集成,所以您不需要配置 "Deploy artifacts to Maven repository"。相反,屏幕截图中显示的以下配置会将您的项目工件部署到工件。
"Deploy artifact to artifactory"
上下文: 我正在尝试通过安装在离线环境(无互联网连接)中的 Jenkins 在 Maven 项目上进行简单构建(不是通过管道作业)。构建成功,我看到 HelloMaven.jar 成功部署到再次离线安装的 JFrog artifactory。
问题: 但是整个 Jenkins 构建失败的原因是
"Build Step:Deploy artifacts to Maven Repository changed build result to FAILURE"
Jenkins 构建控制台输出如下:
Started by user admin
Building in workspace C:\Users\dipakrai\.jenkins\workspace\HelloMaven
Updating https://myownlaptop/svn/HelloMavenDemo/HelloMaven at revision '2017-07-13T11:51:44.844 +0530'
Using sole credentials admin/****** (SVN) in realm <https://myownlaptop.com:443> VisualSVN Server
At revision 6
No changes for https://myownlaptop.com/svn/HelloMavenDemo/HelloMaven since the previous build
Parsing POMs
Established TCP socket on 62532
[HelloMaven] $ "C:\Program Files\Java\jdk1.8.0_65/bin/java" -cp "C:\Users\dipakrai\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-agent-1.11.jar;C:\Program Files\Apache Software Foundation\apache-maven-3.0.3\boot\plexus-classworlds-2.4.jar" org.jvnet.hudson.maven3.agent.Maven3Main "C:\Program Files\Apache Software Foundation\apache-maven-3.0.3" C:\Users\dipakrai\.jenkins\war\WEB-INF\lib\remoting-3.7.jar C:\Users\dipakrai\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-1.11.jar C:\Users\dipakrai\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.11.jar 62532
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven: -B -f C:\Users\dipakrai\.jenkins\workspace\HelloMaven\pom.xml deploy
[INFO] Scanning for projects...
[HUDSON] Collecting dependencies info
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building HelloMaven 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- buildnumber-maven-plugin:1.3:create (default) @ HelloMaven ---
[INFO] Executing: cmd.exe /X /C "svn --non-interactive info"
[INFO] Working directory: C:\Users\dipakrai\.jenkins\workspace\HelloMaven
[INFO] Storing buildNumber: null at timestamp: 1499926911471
[INFO] Executing: cmd.exe /X /C "svn --non-interactive info"
[INFO] Working directory: C:\Users\dipakrai\.jenkins\workspace\HelloMaven
[INFO] Storing buildScmBranch: UNKNOWN_BRANCH
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ HelloMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ HelloMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ HelloMaven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\dipakrai\.jenkins\workspace\HelloMaven\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ HelloMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ HelloMaven ---
[INFO] No tests to run.
[INFO] Surefire report directory: C:\Users\dipakrai\.jenkins\workspace\HelloMaven\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[JENKINS] Recording test results
[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ HelloMaven ---
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ HelloMaven ---
[INFO] Installing C:\Users\dipakrai\.jenkins\workspace\HelloMaven\target\HelloMaven.jar to C:\Users\dipakrai\.m2\repository\net\roseindia\maven\quickstart\HelloMaven.0-SNAPSHOT\HelloMaven-1.0-SNAPSHOT.jar
[INFO] Installing C:\Users\dipakrai\.jenkins\workspace\HelloMaven\pom.xml to C:\Users\dipakrai\.m2\repository\net\roseindia\maven\quickstart\HelloMaven.0-SNAPSHOT\HelloMaven-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ HelloMaven ---
Downloading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar (4 KB at 18.4 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.pom
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.pom (4 KB at 8.6 KB/sec)
Downloading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml (784 B at 16.3 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml (298 B at 1.5 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.064s
[INFO] Finished at: Thu Jul 13 11:51:55 IST 2017
[INFO] Final Memory: 15M/247M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving C:\Users\dipakrai\.jenkins\workspace\HelloMaven\pom.xml to net.roseindia.maven.quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-SNAPSHOT.pom
[JENKINS] Archiving C:\Users\dipakrai\.jenkins\workspace\HelloMaven\target\HelloMaven.jar to net.roseindia.maven.quickstart/HelloMaven/1.0-20170713.062154-1/HelloMaven-1.0-20170713.062154-1.jar
Used promoter class: org.jenkinsci.plugins.artifactpromotion.NexusOSSPromotor
channel stopped
Local repository path: [C:\Users\dipakrai\.jenkins\workspace\HelloMaven\target\local-repo]
Started with promotion
Get Artifact and corresponding POM
Checking if POM already exists in releaserepo
POM doesn't exist in release repo, it will be deployed
Downloading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml
##################################################]
Downloaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml ( at 31.9 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.055434-15.jar
##################################################]
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.055434-15.jar ( at 17.5 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.055434-15.pom
##################################################]
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.055434-15.pom ( at 9.3 KB/sec)
Downloading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml
##################################################]
Downloaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml ( at 7.3 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml
##################################################]
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml ( at 10.5 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml
##################################################]
Uploaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/maven-metadata.xml ( at 2.1 KB/sec)
Skipping deletion of artifact from source repo as requested by user
Maven RedeployPublisher use remote maven settings from : C:\Users\dipakrai/.m2/settings.xml
[INFO] Deployment in http://localhost:8081/artifactory/repo1 (id=ArtifactID,uniqueVersion=true)
Deploying the main artifact HelloMaven-1.0-20170713.062154-1.jar
Downloading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml
Downloaded: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/maven-metadata.xml (787 B at 1.9 KB/sec)
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar
Uploading: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.pom
ERROR: Failed to deploy artifacts: Could not transfer artifact net.roseindia.maven.quickstart:HelloMaven:jar:1.0-20170713.062154-1 from/to ArtifactID (http://localhost:8081/artifactory/repo1): Failed to transfer file: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar. Return code is: 401, ReasonPhrase: Unauthorized.
org.apache.maven.artifact.deployer.ArtifactDeploymentException: Failed to deploy artifacts: Could not transfer artifact net.roseindia.maven.quickstart:HelloMaven:jar:1.0-20170713.062154-1 from/to ArtifactID (http://localhost:8081/artifactory/repo1): Failed to transfer file: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar. Return code is: 401, ReasonPhrase: Unauthorized.
at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:143)
at hudson.maven.reporters.MavenArtifactRecord.deploy(MavenArtifactRecord.java:193)
at hudson.maven.RedeployPublisher.perform(RedeployPublisher.java:176)
at hudson.tasks.BuildStepMonitor.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:735)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:676)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1072)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:621)
at hudson.model.Run.execute(Run.java:1760)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:542)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:405)
Caused by: org.eclipse.aether.deployment.DeploymentException: Failed to deploy artifacts: Could not transfer artifact net.roseindia.maven.quickstart:HelloMaven:jar:1.0-20170713.062154-1 from/to ArtifactID (http://localhost:8081/artifactory/repo1): Failed to transfer file: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar. Return code is: 401, ReasonPhrase: Unauthorized.
at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:317)
at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:245)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.deploy(DefaultRepositorySystem.java:420)
at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:139)
... 11 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact net.roseindia.maven.quickstart:HelloMaven:jar:1.0-20170713.062154-1 from/to ArtifactID (http://localhost:8081/artifactory/repo1): Failed to transfer file: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar. Return code is: 401, ReasonPhrase: Unauthorized.
at org.eclipse.aether.connector.basic.ArtifactTransportListener.transferFailed(ArtifactTransportListener.java:43)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:355)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector.put(BasicRepositoryConnector.java:274)
at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:311)
... 14 more
Caused by: org.apache.maven.wagon.TransferFailedException: Failed to transfer file: http://localhost:8081/artifactory/repo1/net/roseindia/maven/quickstart/HelloMaven/1.0-SNAPSHOT/HelloMaven-1.0-20170713.062154-1.jar. Return code is: 401, ReasonPhrase: Unauthorized.
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:631)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:553)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:535)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:529)
at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:509)
at org.eclipse.aether.transport.wagon.WagonTransporter$PutTaskRunner.run(WagonTransporter.java:644)
at org.eclipse.aether.transport.wagon.WagonTransporter.execute(WagonTransporter.java:427)
at org.eclipse.aether.transport.wagon.WagonTransporter.put(WagonTransporter.java:410)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$PutTaskRunner.runTask(BasicRepositoryConnector.java:510)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:350)
... 16 more
[INFO] Deployment failed after 0.55 sec
Build step 'Deploy artifacts to Maven repository' changed build result to FAILURE
Finished: FAILURE
我的 HelloMaven 项目的 pom.xml 文件条目如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.roseindia.maven.quickstart</groupId>
<artifactId>HelloMaven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>HelloMaven</name>
<scm>
<connection>scm:svn:https://mylaptop/svn/myRepo/</connection>
</scm>
<build>
<finalName>HelloMaven</finalName>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<outputDirectory>${project.basedir}/target/classes</outputDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<archive>
<manifestEntries>
<SCM-Revision>${buildNumber}</SCM-Revision>
</manifestEntries>
</archive>
<webResources>
<resource>
<directory>${project.build.directory}/${project.build.finalName}</directory>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<targetPath>WEB-INF/classes</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>-->
<distributionManagement>
<repository>
<id>artifactory</id>
<name>HelloMaven-release</name>
<url>http://localhost:8081/artifactory/repo1</url>
</repository>
</distributionManagement>
</project>
MAVENm2文件夹的settings.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--<localRepository>C:\Users\dipakrai\.m2\repository</localRepository>-->
<pluginGroups>
<!-- Nothing is present now-->
</pluginGroups>
<proxies>
<!-- Nothing is present now-->
</proxies>
<servers>
<server>
<username>admin</username>
<password>{v2akWC7LO8QHuoPFXESAScpHLzTFzcIKG054oyvz/nc=}</password>
<id>central</id>
</server>
<server>
<username>admin</username>
<password>{v2akWC7LO8QHuoPFXESAScpHLzTFzcIKG054oyvz/nc=}</password>
<id>snapshots</id>
</server>
</servers>
<mirrors>
<mirror>
<id>artifactory</id>
<url>http://localhost:8081/artifactory/repo1</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>artifadeploymentRepoctory</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>HelloMaven-release</name>
<url>http://localhost:8081/artifactory/repo1</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>HelloMaven-snapshot</name>
<url>http://localhost:8081/artifactory/repo1</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
在过去的四天里,我一直在努力解决这个问题,并浏览了很多帖子 Infrastructure with maven, Jenkins, Nexus。我不确定我哪里出错了。 任何线索将不胜感激。
检查 mvn help:effective-settings
returns 以仔细检查您的 user/password 是否确实被使用了。
仔细检查 username/password 是否与 displayed here 匹配,其中 Atifactory 生成加密密码。
最后,在 this post 之后,避免将“central
”作为 ID。
@VonC 上面的回答帮助我解决了这个问题。我在 settings.xml
文件中输入的服务器 ID 与 Jenkins 人工制品配置不匹配。
我进行了以下更改,如下所列。
首先,我更新了我的 Jenkins 人工制品配置,如下所示。 存储库 ID 与 settings.xml 文件中提到的服务器 ID 完全匹配:
<server>
<username>admin</username>
<password>AP447H6DXXJW6WW54BvNBorau5s</password>
<id>artifactory</id>
</server>
并且 settings.xml
文件中下方的存储库 ID 条目必须与上面的服务器 ID 相同:
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>artifactory</id>
<name>myproject-release</name>
<url>http://localhost:8081/artifactory/repo2</url>
</repository>
其次,虽然我没有明确地测试过这个但它必须是这样的: 项目 pom.xml 文件中的 条目也应该与必须发布分发二进制文件的存储库具有相同的 ID(在这种情况下,人工制品)。
<distributionManagement>
<repository>
<id>artifactory</id>
<name>HelloMaven-release</name>
<url>http://localhost:8081/artifactory/repo1</url>
</repository>
</distributionManagement>
或者,因为您已经将 JFrog 工件与 Jenkins 集成,所以您不需要配置 "Deploy artifacts to Maven repository"。相反,屏幕截图中显示的以下配置会将您的项目工件部署到工件。
"Deploy artifact to artifactory"