记录在jenkins中自动部署maven项目时碰到的一些问题
创始人
2024-11-17 16:35:44
0

第一个问题仓库目录权限导致的构建报错

Parsing POMs 00:24:53 Failed to transfer Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.3.0.RELEASE from/to alimaven (https://maven.aliyun.com/nexus/content/groups/public/): /opt/maven/repository/org/springframework/boot/spring-boot-starter-parent/2.3.0.RELEASE/spring-boot-starter-parent-2.3.0.RELEASE.pom.part.lock (No such file or directory) 00:24:53 ERROR: Failed to parse POMs 00:24:53 org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs: 00:24:53 [FATAL] Non-resolvable parent POM for com.xzz.test:Test:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.3.0.RELEASE from/to alimaven (https://maven.aliyun.com/nexus/content/groups/public/): /opt/maven/repository/org/springframework/boot/spring-boot-starter-parent/2.3.0.RELEASE/spring-boot-starter-parent-2.3.0.RELEASE.pom.part.lock (No such file or directory) and 'parent.relativePath' points at wrong local POM @ line 16, column 10 00:24:53  00:24:53 	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:397) 00:24:53 	at hudson.maven.MavenEmbedder.buildProjects(MavenEmbedder.java:370) 00:24:53 	at hudson.maven.MavenEmbedder.readProjects(MavenEmbedder.java:340) 00:24:53 	at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1330) 00:24:53 	at hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1124) 00:24:53 	at hudson.FilePath.act(FilePath.java:1192) 00:24:53 	at hudson.FilePath.act(FilePath.java:1175) 00:24:53 	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.parsePoms(MavenModuleSetBuild.java:985) 00:24:53 	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:689) 00:24:53 	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:526) 00:24:53 	at hudson.model.Run.execute(Run.java:1900) 00:24:53 	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543) 00:24:53 	at hudson.model.ResourceController.execute(ResourceController.java:101) 00:24:53 	at hudson.model.Executor.run(Executor.java:442) 00:24:53 SSH: Connecting from host [020f4f5ad58e] 00:24:53 SSH: Connecting with configuration [dockerCentos] ... 00:24:53 SSH: Creating session: username [root], hostname [192.168.47.210], port [2,222] 00:24:53 SSH: Connecting session ... 00:25:13 SSH: Connected 00:25:13 SSH: Opening SFTP channel ... 00:25:13 SSH: SFTP channel open 00:25:13 SSH: Connecting SFTP channel ... 00:25:21 ERROR: Exception when publishing, exception message [Failed to connect and initialize SSH connection. Message: [Failed to connect SFTP channel. Message [channel is not opened.]]] 00:25:21 Build step 'Send files or execute commands over SSH' changed build result to UNSTABLE 00:25:21 Finished: FAILURE  

这个报错就是从解析pom开始报错的,由于我的仓库目录是/opt/maven/repository/,jenkins没有权限访问导致此报错,只要放开权限就行了

先进入到/opt/maven目录,然后再执行下面命令即可解决报错问题 chmod -R o+r+w repository 

第二个问题编译的jdk版本与实际的版本不一致

Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 02:04:25 	at java.lang.ClassLoader.defineClass1(Native Method) 02:04:25 	at java.lang.ClassLoader.defineClass(ClassLoader.java:756) 02:04:25 	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 02:04:25 	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473) 02:04:25 	at java.net.URLClassLoader.access$100(URLClassLoader.java:74) 02:04:25 	at java.net.URLClassLoader$1.run(URLClassLoader.java:369) 02:04:25 	at java.net.URLClassLoader$1.run(URLClassLoader.java:363) 02:04:25 	at java.security.AccessController.doPrivileged(Native Method) 02:04:25 	at java.net.URLClassLoader.findClass(URLClassLoader.java:362) 02:04:25 	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:425) 02:04:25 	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42) 02:04:25 	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271) 02:04:25 	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247) 02:04:25 	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239) 02:04:25 	at jenkins.maven3.agent.Maven35Main.main(Maven35Main.java:136) 02:04:25 	at jenkins.maven3.agent.Maven35Main.main(Maven35Main.java:66) 

这个报错和jdk版本有关,主要我用的jenkins默认的jdk是11,而我的项目使用的是8,所以在编译java8一类的项目时,总会出现这个报错,但是对整体流程影响不大。jenkins依然可以构建成功。

第三个问题jenkins构建jar包成功了,但是却没有把jar传送到远程服务器上执行,一般这种是由于路径配置的有问题。```

00:20:36 Started by user xiezz 00:20:36 Running as SYSTEM 00:20:36 Building in workspace /var/jenkins_home/workspace/MavenTest 00:20:36 The recommended git tool is: NONE 00:20:36 using credential xiezz 00:20:36  > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/MavenTest/.git # timeout=10 00:20:36 Fetching changes from the remote Git repository 00:20:37  > git config remote.origin.url http://192.168.47.210:8090/xiezz/test.git # timeout=10 00:20:37 Fetching upstream changes from http://192.168.47.210:8090/xiezz/test.git 00:20:37  > git --version # timeout=10 00:20:37  > git --version # 'git version 2.30.2' 00:20:37 using GIT_ASKPASS to set credentials xiezz 00:20:37  > git fetch --tags --force --progress -- http://192.168.47.210:8090/xiezz/test.git +refs/heads/*:refs/remotes/origin/* # timeout=10 00:20:37  > git rev-parse refs/remotes/origin/main^{commit} # timeout=10 00:20:37 Checking out Revision b8407aa96ddd583d9fdccd1500afa87926bf136b (refs/remotes/origin/main) 00:20:37  > git config core.sparsecheckout # timeout=10 00:20:37  > git checkout -f b8407aa96ddd583d9fdccd1500afa87926bf136b # timeout=10 00:20:37 Commit message: "fix:修改pom中的springboot的parent的版本信息" 00:20:37  > git rev-list --no-walk b8407aa96ddd583d9fdccd1500afa87926bf136b # timeout=10 00:20:38 Parsing POMs 00:20:41 Established TCP socket on 40344 00:20:41 [Test] $ /var/jenkins_home/jdk8/bin/java -cp /var/jenkins_home/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.14.jar:/opt/maven/boot/plexus-classworlds-2.6.0.jar:/opt/maven/conf/logging jenkins.maven3.agent.Maven35Main /opt/maven /var/jenkins_home/war/WEB-INF/lib/remoting-3107.v665000b_51092.jar /var/jenkins_home/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.14.jar /var/jenkins_home/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.14.jar 40344 00:20:42 Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 00:20:42 	at java.lang.ClassLoader.defineClass1(Native Method) 00:20:42 	at java.lang.ClassLoader.defineClass(ClassLoader.java:756) 00:20:42 	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 00:20:42 	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473) 00:20:42 	at java.net.URLClassLoader.access$100(URLClassLoader.java:74) 00:20:42 	at java.net.URLClassLoader$1.run(URLClassLoader.java:369) 00:20:42 	at java.net.URLClassLoader$1.run(URLClassLoader.java:363) 00:20:42 	at java.security.AccessController.doPrivileged(Native Method) 00:20:42 	at java.net.URLClassLoader.findClass(URLClassLoader.java:362) 00:20:42 	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:425) 00:20:42 	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42) 00:20:42 	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271) 00:20:42 	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247) 00:20:42 	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239) 00:20:42 	at jenkins.maven3.agent.Maven35Main.main(Maven35Main.java:136) 00:20:42 	at jenkins.maven3.agent.Maven35Main.main(Maven35Main.java:66) 00:20:42 ERROR: ================================================================================ 00:20:42 ERROR: Invalid project setup: Connection reset 00:20:42 ERROR: [JENKINS-18403][JENKINS-28294] JDK 'jdk8' not supported to run Maven projects. 00:20:42 ERROR: Maven projects have to be launched with a Java version greater or equal to the minimum version required by the controller. 00:20:42 ERROR: Use the Maven JDK Toolchains (plugin) to build your maven project with an older JDK. 00:20:42 ERROR: Retrying with agent Java and setting compile/test properties to point to /var/jenkins_home/jdk8. 00:20:42 ERROR: ================================================================================ 00:20:42 Established TCP socket on 38203 00:20:42 [Test] $ /opt/java/openjdk/bin/java -cp /var/jenkins_home/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.14.jar:/opt/maven/boot/plexus-classworlds-2.6.0.jar:/opt/maven/conf/logging jenkins.maven3.agent.Maven35Main /opt/maven /var/jenkins_home/war/WEB-INF/lib/remoting-3107.v665000b_51092.jar /var/jenkins_home/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.14.jar /var/jenkins_home/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.14.jar 38203 00:20:42 <===[JENKINS REMOTING CAPACITY]===>channel started 00:20:49 Executing Maven:  -B -f /var/jenkins_home/workspace/MavenTest/Test/pom.xml -s /opt/maven/conf/settings.xml -gs /opt/maven/conf/settings.xml clean package -U -Dmaven.test.skip=true 00:20:52 [INFO] Scanning for projects... 00:20:52 [INFO]  00:20:52 [INFO] -------------------------< com.xzz.test:Test >-------------------------- 00:20:52 [INFO] Building Test 0.0.1-SNAPSHOT 00:20:52 [INFO]   from pom.xml 00:20:52 [INFO] --------------------------------[ jar ]--------------------------------- 00:20:55 [INFO]  00:20:55 [INFO] --- clean:3.1.0:clean (default-clean) @ Test --- 00:20:56 [INFO] Deleting /var/jenkins_home/workspace/MavenTest/Test/target 00:20:56 [INFO]  00:20:56 [INFO] --- resources:3.1.0:resources (default-resources) @ Test --- 00:20:57 [INFO] Using 'UTF-8' encoding to copy filtered resources. 00:20:57 [INFO] skip non existing resourceDirectory /var/jenkins_home/workspace/MavenTest/Test/src/main/resources 00:20:57 [INFO] skip non existing resourceDirectory /var/jenkins_home/workspace/MavenTest/Test/src/main/resources 00:20:57 [INFO]  00:20:57 [INFO] --- compiler:3.8.1:compile (default-compile) @ Test --- 00:20:58 [INFO] Changes detected - recompiling the module! 00:20:58 [INFO] Compiling 2 source files to /var/jenkins_home/workspace/MavenTest/Test/target/classes 00:21:07 [INFO]  00:21:07 [INFO] --- resources:3.1.0:testResources (default-testResources) @ Test --- 00:21:07 [INFO] Not copying test resources 00:21:07 [INFO]  00:21:07 [INFO] --- compiler:3.8.1:testCompile (default-testCompile) @ Test --- 00:21:07 [INFO] Not compiling test sources 00:21:07 [INFO]  00:21:07 [INFO] --- surefire:2.22.2:test (default-test) @ Test --- 00:21:08 [INFO] Tests are skipped. 00:21:08 [INFO]  00:21:08 [INFO] --- jar:3.2.0:jar (default-jar) @ Test --- 00:21:09 [INFO] Building jar: /var/jenkins_home/workspace/MavenTest/Test/target/Test-0.0.1-SNAPSHOT.jar 00:21:10 [INFO]  00:21:10 [INFO] --- spring-boot:2.3.0.RELEASE:repackage (repackage) @ Test --- 00:21:12 [INFO] Replacing main artifact with repackaged archive 00:21:13 [INFO] ------------------------------------------------------------------------ 00:21:13 [INFO] BUILD SUCCESS 00:21:13 [INFO] ------------------------------------------------------------------------ 00:21:13 [INFO] Total time:  21.343 s 00:21:13 [INFO] Finished at: 2023-03-15T16:21:13Z 00:21:13 [INFO] ------------------------------------------------------------------------ 00:21:13 Waiting for Jenkins to finish collecting data 00:21:14 [JENKINS] Archiving /var/jenkins_home/workspace/MavenTest/Test/pom.xml to com.xzz.test/Test/0.0.1-SNAPSHOT/Test-0.0.1-SNAPSHOT.pom 00:21:14 [JENKINS] Archiving /var/jenkins_home/workspace/MavenTest/Test/target/Test-0.0.1-SNAPSHOT.jar to com.xzz.test/Test/0.0.1-SNAPSHOT/Test-0.0.1-SNAPSHOT.jar 00:21:14 channel stopped 00:21:14 SSH: Connecting from host [020f4f5ad58e] 00:21:14 SSH: Connecting with configuration [dockerCentos] ... 00:21:14 SSH: Creating session: username [root], hostname [192.168.47.210], port [2,222] 00:21:14 SSH: Connecting session ... 00:21:44 SSH: Connected 00:21:44 SSH: Opening SFTP channel ... 00:21:44 SSH: SFTP channel open 00:21:44 SSH: Connecting SFTP channel ... 00:22:10 SSH: Connected 00:22:10 SSH: cd [/] 00:22:10 SSH: OK 00:22:10 SSH: Opening exec channel ... 00:22:10 SSH: EXEC: channel open 00:22:10 SSH: EXEC: STDOUT/STDERR from command [BASE_HOME=/root/data 00:22:10 JAR_NAME=Test-0.0.1-SNAPSHOT.jar 00:22:10 LOG_NAME=out.log 00:22:10 # 停止应用 00:22:10 ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}' | xargs -i kill {} 00:22:10 # 备份日志 00:22:10 if [ -f $BASE_HOME/$LOG_NAME ]; then 00:22:10     mv $BASE_HOME/$LOG_NAME $BASE_HOME/$LOG_NAME.`date +%Y%m%d%H%M%S` 00:22:10 fi 00:22:10 # 备份jar包 00:22:10 if [ -f $BASE_HOME/$JAR_NAME ]; then 00:22:10     cp $BASE_HOME/$JAR_NAME $BASE_HOME/$JAR_NAME.`date +%Y%m%d%H%M%S` 00:22:10 fi 00:22:10 #启动应用 00:22:10 nohup java -jar $BASE_HOME/$JAR_NAME &>$BASE_HOME/$LOG_NAME &] ... 00:22:10 SSH: EXEC: connected 00:22:20 SSH: EXEC: completed after 10,456 ms 00:22:20 SSH: Disconnecting configuration [dockerCentos] ... 00:22:20 SSH: Transferred 0 file(s) 00:22:20 Finished: SUCCESS  

我们可以看到构建是成功的,但是倒数第二行却是0 files,说明并没有传送jar包到远程服务器,此时就需要检查一下ssh中配置的路径和jenkins中的这个项目的的工作空间里的路径是否相同;如下所示:
在这里插入图片描述
我们这里的目录是Test/target/Test-0.0.1-SNAPSHOT.jar,此时我们在ssh的配置中也应该符合这种目录形式:
在这里插入图片描述
这样的话,就可以成功将jar包传到远程服务器了,不过这里也有必要解释一下几个名词的意义:
Source files: 源文件,这个路径就是刚刚我截图工作空间的相对路径,Test/target/Test-0.0.1-SNAPSHOT.jar
Remove prefix:上传到目标服务器时,需要移除jar包之前的路径,上边source file写的是Test/target/Test-0.0.1-SNAPSHOT.jar,这里移除前缀就是Test/target/
Remote directory:上传到目标服务器的那个目录下,之前ssh配置信息的是/, 这里写的是root/data,那么文件就会上传到目标服务器的 /root/data 下.
这个问题的详细解答可以参考另一个大神的博客,传送门

相关内容

热门资讯

2分钟细说!wpk德州辅助(软... 2分钟细说!wpk德州辅助(软件透明挂)同城跑胡子有猫腻的(有挂总结)准备好在wepoke ia的高...
4分钟秒懂!微扑克德州辅助(透... 4分钟秒懂!微扑克德州辅助(透视插件)微扑克德州果真真的有挂的(有挂启发)是一款可以让一直输的玩家,...
带你了解!wpk机器人软件(软... 《带你了解!wpk机器人软件(软件透明挂)钱塘十三水有漏洞的(有挂技巧)》 wpk软件透明挂更新公告...
3分钟秒懂!WePOker辅助... 3分钟秒懂!WePOker辅助挂(透视脚本)WePOker果然是有猫腻的(有挂引领);玩家必备必赢加...
揭秘!微扑克ai辅助会封号的(... 揭秘!微扑克ai辅助会封号的(透视)星悦陕西麻将神器(有挂辅导);本章节将是从实际的德州星悦陕西麻将...
五分钟透视!wepOKer是有... 五分钟透视!wepOKer是有透视软件(透视作弊)wepOKer其实真的是有挂的(有挂策略);玩家必...
我来教大家!德州wpk德州真的... 《我来教大家!德州wpk德州真的假的(透明挂)开心十三张辅助挂(有挂途径)》 wpk软件透明挂更新公...
如何把彩色cad转成黑白pdf... 在CAD软件中,将图纸设置为黑白模式,然后选择打印,打印机选择“DWG to PDF”,再在打印设置...
手机文件夹里那些可以删除 手机文件夹中,通常可以删除的是缓存文件、临时文件、下载的应用程序安装包等。但需注意,不要删除系统文件...
梦幻新诛仙手游各个职业加点(梦... 梦幻新诛仙手游中,各职业加点需根据角色定位。如青云注重法术攻击,可主加智力;鬼王宗则偏重物理防御,可...