解決The goal you specified requires a project to execute but there is no POM in this directory錯誤的一種方法!
阿新 • • 發佈:2019-02-08
在使用Jenkins自動構建Java專案時,出現以下的錯誤。錯誤日誌如下:
+ /opt/maven/apache-maven-3.5.4/bin/mvn clean package -U -e -B -Dmaven.test.skip=true [INFO] Error stacktraces are turned on. [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.096 s [INFO] Finished at: 2018-10-17T19:09:42+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/root/.jenkins/workspace). Please verify you invoked Maven from the correct directory. -> [Help 1] org.apache.maven.lifecycle.MissingProjectException: The goal you specified requires a project to execute but there is no POM in this directory (/root/.jenkins/workspace/). Please verify you invoked Maven from the correct directory. at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:85) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:954) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288) at org.apache.maven.cli.MavenCli.main (MavenCli.java:192) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) [ERROR] [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/MissingProjectException Build step '執行 shell' marked build as failure SSH: Current build result is [FAILURE], not going to run. Finished: FAILURE
去網上搜了一遍發現各種解決辦法,但是沒有什麼作用。仔細分析了下文章中日誌中的意思無非就是找不到POM檔案。我去Jenkins的workspace裡去檢視發現下面多了一級子目錄,也就是說pom檔案不在workspace中的工程目錄中。所以就會導致maven找不到pom檔案。所以,我在構建的時候直接在構建前加一個進入工程實際目錄的動作,在進行構建,就不會有問題了。
如下圖:
就能直接構建成功了。這是最簡便的方式。
事後分析了下造成這種情況:大概是拉取程式碼分支,程式碼分支裹了一層目錄,所以拉過來就多了一級目錄。