標籤:工具 plugin init run task ati 技術分享 start 技術
jenkins構建java項目時出現的報錯情況:
$ mvn clean installFATAL: command execution failedjava.io.IOException: error=2, No such file or directoryat java.lang.UNIXProcess.forkAndExec(Native Method)at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)at java.lang.ProcessImpl.start(ProcessImpl.java:134)at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)Caused: java.io.IOException: Cannot run program "mvn" (in directory "/var/lib/jenkins/workspace/es"): error=2, No such file or directory
報錯情況2:
/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven_3.5.3/bin/mvn clean installwhich: no java in (/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven_3.5.3/bin:/sbin:/usr/sbin:/bin:/usr/bin)The JAVA_HOME environment variable is not defined correctlyThis environment variable is needed to run this programNB: JAVA_HOME should point to a JDK not a JREBuild step ‘Invoke top-level Maven targets‘ marked build as failureFinished: FAILURE
報錯情況3:
[INFO] Changes detected - recompiling the module![INFO] Compiling 33 source files to /var/lib/jenkins/workspace/es/target/classes[INFO] -------------------------------------------------------------[ERROR] COMPILATION ERROR : [INFO] -------------------------------------------------------------[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?[INFO] 1 error[INFO] -------------------------------------------------------------[INFO] ------------------------------------------------------------------------[INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[INFO] Total time: 02:42 min[INFO] Finished at: 2018-05-29T18:32:22+08:00[INFO] ------------------------------------------------------------------------[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project ruhnn-visual-search-background: Compilation failure[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?[ERROR] [ERROR] -> [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/MojoFailureException
解決方案:
安裝maven 並配置到jenkins配置裡 https://maven.apache.org/download.cgiwget http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.tar.gztar zxvf apache-maven-3.5.2-bin.tar.gzmv apache-maven-3.5.2 /usr/local//usr/loca/apache-maven-3.5.2/bin/mvn --versionjenkins -> 系統管理 -> 全域工具配置Maven Configuration -> Settings file in filesystem -> File Path /usr/local/apache-maven-3.5.2/conf/settings.xmlGlobal settings file on filesystem -> File Path 同上下拉到Maven,Maven安裝,Name(自訂,如maven3.5.2),MAVEN_HOME填 “/usr/local/apache-maven-3.5.2”左下角“save”
安裝maven 也可以參考:http://www.cnblogs.com/weifeng1463/p/8920765.html
安裝jdk jenkins -> 系統管理 -> 全域工具配置JDK安裝JDK 別名 JDK1.8 自動安裝 從java.sun.com 安裝 版本 Java SE Development Kit 8u162
最後測試可以成功構建:
jenkins構建java項目找不到命令mvn,java的解決方案