Jenkins-maven编译异常

Maven编译异常

jenkins maven Name or service not known linux

问题背景

​ 昨天晚上在升级生产环境时遇到一个奇葩问题,相同的代码在生产和测试两个环境表现却不一样。测试环境能够正常发布,生产环境在编译的时候就遇到了Maven远程仓库访问不到的问题。具体情况如下(对项目信息做了部分脱敏):

Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal on project car-interf-core: Could not resolve dependencies for project com.sinosoft.car:car-interf-core:jar:0.1: Failed to collect dependencies at com.sun.xml.bind:jaxb-impl:jar:2.3.1: Failed to read artifact descriptor for com.sun.xml.bind:jaxb-impl:jar:2.3.1: Could not transfer artifact com.sun.xml.bind:jaxb-impl:pom:2.3.1 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-impl/2.3.1/jaxb-impl-2.3.1.pom: Unknown host repo.maven.apache.org: Name or service not known -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :car-interf-core
处理经过

​ 从错误信息可以看出依然是因为访问不到远端maven仓库导致的,起初以为是网络问题,导致访问不到repo.maven.apache.org。于是尝试使用阿里的maven仓库,在maven的settings.xml中配置了仓库地址,如下:

<mirrors>
  <mirror>
    <id>aliyunmaven</id>
    <mirrorOf>*</mirrorOf>
    <name>阿里云公共仓库</name>
    <url>https://maven.aliyun.com/repository/public</url>
  </mirror>
</mirrors>

​ 更换了maven仓库之后还是报Name or service not known错误,只不过变成了阿里的maven仓库地址。如下:

ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.cloud.fast:fast-cloud-parent:0.1: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.1.3.RELEASE from/to aliyun (https://maven.aliyun.com/repository/public): maven.aliyun.com: Name or service not known @ com.cloud.xxx:xxx-xxx-parent:0.1, /root/.m2/repository/com/cloud/xxx/xxx-xxx-parent/0.1/xxx-xxx-parent-0.1.pom, line 5, column 13

	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:383)
	at hudson.maven.MavenEmbedder.buildProjects(MavenEmbedder.java:370)
	at hudson.maven.MavenEmbedder.readProjects(MavenEmbedder.java:340)
	at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1327)
	at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1124)
	at hudson.FilePath.act(FilePath.java:1163)
	at hudson.FilePath.act(FilePath.java:1146)
	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.parsePoms(MavenModuleSetBuild.java:985)
	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:689)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:514)
	at hudson.model.Run.execute(Run.java:1907)
	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)

​ 从报错信息可以看出,依然是Name or service not known错误。

​ 看到目前这种情况我意识到,这不是简简单单maven仓库的问题了,个问题可能已经上升到了网络层面。于是我拿repo.maven.apache.org这个地址尝试在服务器上访问一下试试:

[root@hero]# ping repo.maven.apache.org
ping: repo.maven.apache.org: 未知的名称或服务

​ 起初以为这是正常情况,在我的认知中这个域名是有问题的(怪我才疏学浅,只知道二级域名),访问不到也是正常。但我还是好奇的在另外一台服务器上尝试了一下,这下直接改变了我的认知:

[root@hero]# ping repo.maven.apache.org
PING maven.map.fastly.net (151.101.24.215) 56(84) bytes of data.
64 bytes from 151.101.24.215 (151.101.24.215): icmp_seq=1 ttl=49 time=164 ms
64 bytes from 151.101.24.215 (151.101.24.215): icmp_seq=2 ttl=49 time=164 ms

​ 这下真是长记性了,这样的域名也是能正常访问的。通过这样一对比,感觉问题已经很明朗了,就是网络的问题嘛。但我拿到解析出来的ip地址在Jenkins服务器上尝试Ping了一下,就出现这样的情况:

[root@root]# ping 151.101.40.215
PING 151.101.40.215 (151.101.40.215) 56(84) bytes of data.
64 bytes from 151.101.40.215: icmp_seq=1 ttl=49 time=169 ms
64 bytes from 151.101.40.215: icmp_seq=2 ttl=49 time=169 ms

​ 很惭愧,我的猜测又错了,网络没问题。这下我就更懵逼了,完全就失去了方向。于是我带着侥幸的心里尝试在度娘上看能不能找到解决方案。 很庆幸,在百度的第一个搜索结果就把问题给解决了,虽然和博主的情况不一样。但目的达到了。

https://www.cnblogs.com/passer101/p/9899202.html

​ 博客中提到可能是网卡的问题,我按照博主的步骤一步一步排查,并没有什么大问题。但我用了博主的第三步:
在这里插入图片描述
​ 没错,我也见证了奇迹。

[root@root]# service network restart
Restarting network (via systemctl):                        [  OK  ]
[root@root]# ping repo.maven.apache.org
PING maven.map.fastly.net (151.101.24.215) 56(84) bytes of data.
64 bytes from 151.101.24.215 (151.101.24.215): icmp_seq=1 ttl=49 time=164 ms
64 bytes from 151.101.24.215 (151.101.24.215): icmp_seq=2 ttl=49 time=164 ms

​ 哦吼,能正常访问了。

处理结果

​ 经过以上的排查和操作,接下来要验证一下看真正面临的问题有没有解决掉,于是在Jenkins上重新尝试编译项目,如下:

[INFO] ------------------< com.sinosoft.car:car-interf-core >------------------
[INFO] Building car-interf-core 0.1                                       [3/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-impl/2.3.1/jaxb-impl-2.3.1.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-impl/2.3.1/jaxb-impl-2.3.1.pom (15 kB at 2.4 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/mvn/jaxb-bundles/2.3.1/jaxb-bundles-2.3.1.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/mvn/jaxb-bundles/2.3.1/jaxb-bundles-2.3.1.pom (2.9 kB at 2.6 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/mvn/jaxb-parent/2.3.1/jaxb-parent-2.3.1.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/mvn/jaxb-parent/2.3.1/jaxb-parent-2.3.1.pom (41 kB at 3.8 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-bom-ext/2.3.1/jaxb-bom-ext-2.3.1.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-bom-ext/2.3.1/jaxb-bom-ext-2.3.1.pom (5.0 kB at 4.3 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/glassfish/jaxb/jaxb-bom/2.3.1/jaxb-bom-2.3.1.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/glassfish/jaxb/jaxb-bom/2.3.1/jaxb-bom-2.3.1.pom (10 kB at 6.7 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/glassfish/jaxb/jaxb-runtime/2.3.1/jaxb-runtime-2.3.1.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/glassfish/jaxb/jaxb-runtime/2.3.1/jaxb-runtime-2.3.1.pom (7.8 kB at 4.4 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/mvn/jaxb-runtime-parent/2.3.1/jaxb-runtime-parent-2.3.1.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/mvn/jaxb-runtime-parent/2.3.1/jaxb-runtime-parent-2.3.1.pom (2.8 kB at 1.7 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/glassfish/jaxb/txw2/2.3.1/txw2-2.3.1.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/glassfish/jaxb/txw2/2.3.1/txw2-2.3.1.pom (4.3 kB at 5.8 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/mvn/jaxb-txw-parent/2.3.1/jaxb-txw-parent-2.3.1.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/mvn/jaxb-txw-parent/2.3.1/jaxb-txw-parent-2.3.1.pom (2.8 kB at 1.5 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/istack/istack-commons-runtime/3.0.7/istack-commons-runtime-3.0.7.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/istack/istack-commons-runtime/3.0.7/istack-commons-runtime-3.0.7.pom (5.9 kB at 3.2 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/istack/istack-commons/3.0.7/istack-commons-3.0.7.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/istack/istack-commons/3.0.7/istack-commons-3.0.7.pom (14 kB at 5.1 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/jvnet/staxex/stax-ex/1.8/stax-ex-1.8.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/jvnet/staxex/stax-ex/1.8/stax-ex-1.8.pom (15 kB at 4.7 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/xml/fastinfoset/FastInfoset/1.2.15/FastInfoset-1.2.15.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/xml/fastinfoset/FastInfoset/1.2.15/FastInfoset-1.2.15.pom (6.9 kB at 2.5 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/xml/fastinfoset/fastinfoset-project/1.2.15/fastinfoset-project-1.2.15.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/xml/fastinfoset/fastinfoset-project/1.2.15/fastinfoset-project-1.2.15.pom (14 kB at 7.0 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/pdfbox/pdfbox/2.0.4/pdfbox-2.0.4.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/pdfbox/pdfbox/2.0.4/pdfbox-2.0.4.pom (8.3 kB at 5.6 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/pdfbox/pdfbox-parent/2.0.4/pdfbox-parent-2.0.4.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/pdfbox/pdfbox-parent/2.0.4/pdfbox-parent-2.0.4.pom (13 kB at 6.2 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/pdfbox/fontbox/2.0.4/fontbox-2.0.4.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/pdfbox/fontbox/2.0.4/fontbox-2.0.4.pom (2.4 kB at 745 B/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-impl/2.3.1/jaxb-impl-2.3.1.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/glassfish/jaxb/jaxb-runtime/2.3.1/jaxb-runtime-2.3.1.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/glassfish/jaxb/txw2/2.3.1/txw2-2.3.1.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/istack/istack-commons-runtime/3.0.7/istack-commons-runtime-3.0.7.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/jvnet/staxex/stax-ex/1.8/stax-ex-1.8.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/istack/istack-commons-runtime/3.0.7/istack-commons-runtime-3.0.7.jar (26 kB at 11 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/com/sun/xml/fastinfoset/FastInfoset/1.2.15/FastInfoset-1.2.15.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/jvnet/staxex/stax-ex/1.8/stax-ex-1.8.jar (36 kB at 15 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/pdfbox/pdfbox/2.0.4/pdfbox-2.0.4.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/glassfish/jaxb/txw2/2.3.1/txw2-2.3.1.jar (70 kB at 29 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/pdfbox/fontbox/2.0.4/fontbox-2.0.4.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/xml/fastinfoset/FastInfoset/1.2.15/FastInfoset-1.2.15.jar (312 kB at 88 kB/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/pdfbox/pdfbox/2.0.4/pdfbox-2.0.4.jar (2.5 MB at 192 kB/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/pdfbox/fontbox/2.0.4/fontbox-2.0.4.jar (1.5 MB at 14 kB/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/glassfish/jaxb/jaxb-runtime/2.3.1/jaxb-runtime-2.3.1.jar (1.1 MB at 9.4 kB/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-impl/2.3.1/jaxb-impl-2.3.1.jar (1.1 MB at 6.6 kB/s)

​ 努力的结果没白费(奇迹出现了)。

​ 最终项目也完美的:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
总结

​ 经过这次问题的处理,我意识到了自己的知识储备还不够充足。在看到这个问题的时候第一时间想到的是jenkins配置问题、maven配置问题、网络问题,唯独没想到是网卡的问题。问题都已经解决了,但还是没找到网卡出现问题的原因,究竟是什么导致的。

​ 在这里还是很感谢https://www.cnblogs.com/passer101/p/9899202.html这位博主的分享,帮助我解决了问题。

原创不易,转发请标注来源,谢谢...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值