Jenkins Pipeline集成JFrog Artifactory构建Maven时插件解析失败求助
Maven 集成JFrog的Pipeline构建问题
原始报错信息
[main] ERROR org.apache.maven.cli.MavenCli - Plugin org.apache.maven.plugins:maven-clean-plugin:3.1.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:3.1.0: Could not find artifact org.apache.maven.plugins:maven-plugins:pom:31 in artifactory-release (http://localhost:8081/artifactory/libs-release) -> [Help 1]
现有配置
Jenkins Pipeline 代码
node { def server def buildInfo def rtMaven def mvnHome = tool 'Maven3' stage ("checkout") { git 'your-project-repo-url' } stage ('Artifactory configuration') { server = Artifactory.server('artifactory-server'); rtMaven = Artifactory.newMavenBuild() rtMaven.tool = 'Maven3' rtMaven.deployer releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot-local', server: server rtMaven.resolver releaseRepo: 'libs-release', snapshotRepo: 'libs-snapshot', server: server buildInfo = Artifactory.newBuildInfo() } stage ('Build') { rtMaven.run -X pom: 'pom.xml', goals: 'clean install', buildInfo: buildInfo } stage ('Upload Artifacts') { rtMaven.deployer.deployArtifacts buildInfo server.publishBuildInfo buildInfo } }
Maven settings.xml 配置片段
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <proxies> <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> <username>proxyuser</username> <password>proxypass</password> <host>proxy.host.net</host> <port>80</port> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> </proxies> <servers> <server> <id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password> </server> <server> <id>siteServer</id> <privateKey>/path/to/private/key</privateKey> <passphrase>optional; leave empty if not used.</passphrase> </server> </servers> <mirrors> <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Mirror repository</name> <url>http://my.repository.com/repo/path</url> </mirror> </mirrors> <profiles> <profile> <id>jdk-1.4</id> <activation> <jdk>1.4</jdk> </activation> <repositories> <repository> <id>jdk14</id> <name>Repository for JDK 1.4 builds</name> <url>http://www.myhost.com/maven/jdk14</url> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile> <profile> <id>env-dev</id> <activation> <property> <name>target-env</name> <value>dev</value> </property> </activation> <properties> <tomcatPath>/path/to/tomcat/instance</tomcatPath> </properties> </profile> </profiles> <activeProfiles> <activeProfile>alwaysActiveProfile</activeProfile> <activeProfile>anotherAlwaysActiveProfile</activeProfile> </activeProfiles> </settings>
问题现象
- 本地环境直接执行Maven构建可正常完成依赖解析与构建流程
- 仅在Jenkins Pipeline场景下通过JFrog插件触发构建时,抛出插件依赖无法解析的错误
- 表现为Maven未按预期访问配置的远程仓库拉取构件,仅校验本地缓存后直接报错
根因排查与解决方向
- JFrog Maven插件默认生成独立settings配置,覆盖本地自定义配置:Jenkins上的JFrog插件执行Maven命令时,会自动生成内置的settings.xml文件,不会自动关联自定义的本地settings.xml,原有配置的代理、镜像、仓库认证信息全部不生效,直接导致依赖拉取路径异常。可在
rtMaven.run命令中通过settingsFile参数显式指定自定义settings.xml路径解决。 - 配置的解析仓库类型不匹配:
libs-release如果是纯本地类型仓库,没有配置代理Maven中央仓库的远程存储能力,本身无法存储maven-clean-plugin对应的父级pomorg.apache.maven.plugins:maven-plugins:pom:31,自然会抛出找不到构件的错误。需将解析仓库替换为配置了中央仓库远程代理的虚拟/聚合仓库。 - 报错中的仓库ID与配置不匹配:Pipeline中配置的resolver仓库ID为
libs-release,但报错日志显示拉取源为artifactory-release,说明插件自动生成的Maven配置中,仓库指向与预期配置不一致,可通过-X调试输出查看实际生效的Maven仓库列表。 - Jenkins节点本地Maven仓库缓存损坏:Jenkins运行节点上的本地Maven仓库路径存在元数据损坏的构件时,Maven会直接判定构件不可用且不触发远程拉取。可清空Jenkins节点上的
~/.m2/repository缓存后重试构建。
内容的提问来源于stack exchange,提问作者Ankit Kumar
相关产品推荐
相关产品推荐

