jenkins构建项目-配置JDK的JAVA_HOME路径

项目场景:

Jenkins 2.372 rpm安装方式
jdk 11


问题描述

  1. 配置jdk中警告
/usr/bin/java is not a directory on the Jenkins controller (but perhaps it exists on some agents)

jenkins构建项目-配置JDK的JAVA_HOME路径_第1张图片

  1. 构建过程中出现报错
Parsing POMs
Established TCP socket on 45359
[dev-projectMap] $ /usr/bin/java/bin/java -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.13.jar:/usr/apache-maven-3.6.3/boot/plexus-classworlds-2.6.0.jar:/usr/apache-maven-3.6.3/conf/logging jenkins.maven3.agent.Maven35Main /usr/apache-maven-3.6.3 /var/lib/jenkins/%C/jenkins/war/WEB-INF/lib/remoting-3063.v26e24490f041.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.13.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.13.jar 45359
ERROR: Failed to parse POMs
java.io.IOException: Cannot run program "/usr/bin/java/bin/java" (in directory "/var/lib/jenkins/workspace/dev-projectMap"): error=20, Not a directory
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
	at hudson.Proc$LocalProc.<init>(Proc.java:254)
	at hudson.Proc$LocalProc.<init>(Proc.java:223)
	at hudson.Launcher$LocalLauncher.launch(Launcher.java:997)
	at hudson.Launcher$ProcStarter.start(Launcher.java:509)
	at hudson.maven.AbstractMavenProcessFactory.newProcess(AbstractMavenProcessFactory.java:280)
	at hudson.maven.ProcessCache.get(ProcessCache.java:236)
	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:802)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:526)
	at hudson.model.Run.execute(Run.java:1900)
	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
	at hudson.model.ResourceController.execute(ResourceController.java:107)
	at hudson.model.Executor.run(Executor.java:449)
Caused by: java.io.IOException: error=20, Not a directory
	at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
	at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340)
	at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
	... 13 more
Finished: FAILURE

原因分析:

网上大多在配置jenkinsjdk配置是根据 which java命令的java路径配置,这个配置路径的java是个文件,而不是文件夹。

[root@k8s-node bin]# which java
/usr/bin/java

解决方案:

更改配置路径

  1. 找到java的安装路径,在/etc/profile文件中,安装jdk的JAVA_HOME配置路径
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
export JAVA_HOME=/usr/local/jdk-11.0.16.1
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
export MAVEN_HOME=/usr/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$PATH
  1. 复制上文中的JAVA_HOME路径到【系统管理】->【全局工具设置】->【jdk】配置

jenkins构建项目-配置JDK的JAVA_HOME路径_第2张图片

  1. 同时解决问题描述中连个问题

你可能感兴趣的:(jenkins,java,运维)