Jenkins Pipeline Maven Artifactory插件无法解析来自Central Maven存储库的工件 [英] Jenkins Pipeline Maven Artifactory Plugin Cannot Resolve Artifact From Central Maven Repository
问题描述
使用Jenkins Freestyle项目时,我能够使用"Maven3-Artifactory Integration"成功运行Maven的构建.
When using a Jenkins Freestyle Project I am able to successfully run a build with Maven using the "Maven3-Artifactory Integration."
当尝试在管道中使用此功能时,我遇到了从中央Maven存储库解决工件的问题.我的印象是,当詹金斯无法在人工制品中找到人工制品时,它应该退回到中央Maven存储库, https://repo.maven.apache.org/maven2 ,以查找工件.不是吗?
When trying to use this feature in pipeline I run into issues with resolving artifacts from the central maven repository. I am under the impression that when Jenkins cannot find an artifact in artifactory it should fall back to the central maven repository,https://repo.maven.apache.org/maven2, to look for the artifact. Is this not the case?
def server = Artifactory.server SERVER_ID
def rtMaven = Artifactory.newMavenBuild()
rtMaven.resolver server: server, releaseRepo: 'my-release-local', snapshotRepo: 'my-snapshot-local'
rtMaven.deployer server: server, releaseRepo: 'my-release-local', snapshotRepo: 'my-snapshot-local'
rtMaven.deployer.artifactDeploymentPatterns.addInclude("").addExclude("")
rtMaven.deployer.deployArtifacts = false
rtMaven.tool = MAVEN_TOOL
def buildInfo = rtMaven.run pom: POM_FILE, goals: GOALS
server.publishBuildInfo buildInfo
从控制台输出来看,即使Jenkins看到了中央存储库,似乎仍在强制构建只解析Artifactory中的工件,而没有其他地方.
From the console output it seems like Jenkins is forcing the build to only resolve artifacts from Artifactory and nowhere else, even though it sees the central repo.
[main] DEBUG org.jfrog.build.extractor.maven.resolver.ArtifactoryEclipseRepositoryListener - [buildinfo] Resolved artifact: org.apache.maven.plugins:maven-clean-plugin:pom:2.5:build from: central (https://repo.maven.apache.org/maven2, releases) Context is: plugin
[main] DEBUG org.jfrog.build.extractor.maven.resolver.ResolutionHelper - [buildinfo] Properties file '/tmp/buildInfo6034012728922541318.properties' retrieved from 'System.getProperty(buildInfoConfig.propertiesFile)'
[main] DEBUG org.jfrog.build.extractor.maven.resolver.ArtifactoryEclipseResolversHelper - [buildinfo] Enforcing snapshot repository for resolution: mysnapshotartifactoryURL
[main] DEBUG org.jfrog.build.extractor.maven.resolver.ArtifactoryEclipseResolversHelper - [buildinfo] Enforcing repository authentication: username=myusername, password=*** for snapshot resolution repository
[main] DEBUG org.jfrog.build.extractor.maven.resolver.ArtifactoryEclipseResolversHelper - [buildinfo] Enforcing release repository for resolution: myreleaseartifactoryURL
[main] DEBUG org.jfrog.build.extractor.maven.resolver.ArtifactoryEclipseResolversHelper - [buildinfo] Enforcing repository authentication: username=myusername, password=*** for release resolution repository
[main] DEBUG org.jfrog.build.extractor.maven.resolver.ArtifactoryEclipseArtifactResolver - Verifying availability of /home/myusername/.m2/repository/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom from [artifactory-release (myreleaseartifactoryURL, releases), artifactory-snapshot (mysnapshotartifactoryURL, snapshots)]
[main] DEBUG org.jfrog.build.extractor.maven.resolver.ArtifactoryEclipseRepositoryListener - [buildinfo] Could not resolve artifact: org.apache.maven.plugins:maven-plugins:pom:22:build
[main] ERROR org.apache.maven.cli.MavenCli - Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not find artifact org.apache.maven.plugins:maven-plugins:pom:22 in artifactory-release (myreleaseartifactoryURL)-> [Help 1]
org.apache.maven.plugin.PluginResolutionException: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5
推荐答案
前段时间我遇到了同样的问题.我不知道它是否适用于您.流程是我从人工制品中记得的:
I had the same problem some time ago. I don't know if it applies for you. The flow is what I remember from artifactory:
- 检查我们用于本地构建的
libs-release-local
.这具有虚拟存储库关联和 libs-release - 库发行版是一个虚拟存储库. libs-release下的包含的存储库是 libs-release-local 和 maven-central-custom
- 工件的解析和上载是在 libs-release-local 之间进行的.如果所需的工件不可用,则maven遵循 libs-release-local -> libs-release -> maven-central-custom
- check on
libs-release-local
, which we were using for local builds. this has Virtual Repository Associations with libs-release - libs-release is a virtual repo. And Included Repositories under libs-release are libs-release-local AND maven-central-custom
- Resolution and upload of artifacts is done to/from libs-release-local. Incase the requred artifact is not available, maven is following libs-release-local --> libs-release --> maven-central-custom
以下是我们在jenkinsfile中使用它的方式:
And the following is how we use it inside our jenkinsfile:
// Obtain an Artifactory server instance, defined in Jenkins --> Manage:
def server = Artifactory.server 'localArtifactory'
def rtMaven
def buildInfo
// Artifactory Maven Build instance
rtMaven = Artifactory.newMavenBuild()
rtMaven.tool = 'localMaven'
//where the Maven build should download its dependencies from
rtMaven.resolver server: server, releaseRepo: 'libs-release' , snapshotRepo: 'libs-snapshot'
//define where our build artifacts should be deployed to. we define the Artifactory server and repositories on the 'rtMaven' instance
rtMaven.deployer server: server, releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot-local'
//disable pushing to artifactory, true if requered
rtMaven.deployer.deployArtifacts = false
//By default, all the build artifacts are deployed to Artifactory. So, let's make filter and deployArtifacts=true
rtMaven.deployer.artifactDeploymentPatterns.addInclude("*-common-*")
rtMaven.run pom: 'pom.xml', goals: 'clean package'
rtMaven.deployer.deployArtifacts buildInfo
这篇关于Jenkins Pipeline Maven Artifactory插件无法解析来自Central Maven存储库的工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!