God_Father
God_Father

Reputation: 599

How to stop Maven Execution

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 ?

Upvotes: 6

Views: 29237

Answers (3)

Essex Boy
Essex Boy

Reputation: 7988

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>

Upvotes: 3

ankit
ankit

Reputation: 2845

If you are running linux:

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

Upvotes: 1

Robert Scholte
Robert Scholte

Reputation: 12345

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.

Upvotes: 1

Related Questions