2017-08-31 166 views
0

我有一个模拟服务器,我需要在运行我的自动化测试之前在Jenkins中启动,然后在运行测试后停止模拟服务器。如何停止Maven执行

这个模拟服务器是一个maven项目,正在使用exec-maven-plugin。我可以通过运行命令mvn exec:java来启动此服务器。但是我无法通过Jenkins阻止这个maven项目。我已经阅读了它,大多数答案告诉找到这个Maven项目的进程ID,然后杀死它。有没有更简单更简单的方法来阻止这个项目?

回答

0

您需要使用goals作为maven生命周期的一部分来启动和停止服务器。

this answer

<plugin> 
     <groupId>org.apache.tomcat.maven</groupId> 
     <artifactId>tomcat7-maven-plugin</artifactId> 
     <version>2.1</version> 
     <executions> 
      <execution> 
      <id>tomcat-run</id> 
      <goals> 
       <goal>run-war-only</goal> 
      </goals> 
      <phase>pre-integration-test</phase> 
       <configuration> 

        <fork>true</fork> 
       </configuration> 

      </execution> 
      <execution> 
      <id>tomcat-shutdown</id> 
      <goals> 
       <goal>shutdown</goal> 
      </goals> 
      <phase>post-integration-test</phase> 
      </execution> 
     </executions> 
     </plugin> 
0

的关键带到这个问题的一个例子的确是你不知道的ProcessID。考虑使用exec:exec而不是async。你会发现asyncDestroyOnShutdown默认设置为true,这意味着一旦Maven关闭,它将关闭。