How to stop Maven Execution
Asked Answered
T

3

6

I have a mock server which I need to start in Jenkins before running my Automation tests and then stop the mock server after my tests have run.

This mock server is a maven project and is using exec-maven-plugin. I am able to start this server by running the command mvn exec:java. However I am unable to stop this maven project through Jenkins. I have read about it and most answers tell to find the Process ID of this Maven project and then kill it. Is there a cleaner and easier way to stop this project ?

Typo answered 31/8, 2017 at 6:56 Comment(0)
T
3

You need to start and stop your server using goals which are part of the Maven life cycle.

An example taken from 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>
Tapioca answered 31/8, 2017 at 7:11 Comment(0)
A
1

The key to this issue is indeed that you don't know the processId. Consider using exec:exec instead with async. You'll see that asyncDestroyOnShutdown is set to true by default, meaning it'll shut down once Maven is shutting down.

Ahab answered 31/8, 2017 at 8:45 Comment(0)
V
1

If you are running linux:

ps aux |grep <project-name> and then kill -9 <process id>

Vogler answered 13/8, 2019 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.