简体   繁体   中英

Gradle: How do I stop Jetty if JMeter test failed

How do I stop Jetty if JMeter test failed? My Gradle script:

apply plugin: 'jetty'
apply plugin: 'jmeter'

jmeterRun {
    doFirst() {
        jettyRunWar.httpPort = 8080    // Port for test
        println "Starting Jetty on port:" + jettyRunWar.httpPort

        jettyRunWar.daemon = true
        jettyRunWar.execute()
    }
    doLast() {
        println "Stopping Jetty"

        jettyStopWar.stopPort = 8091   // Port for stop signal
        jettyStopWar.stopKey = 'stopKey'
        jettyStopWar.execute()
    }

    jmeterTestFiles = [
        file("src/test/jmeter/Tests.jmx")
    ]
}

You can use the method finalizedBy to ensure that Jetty is stopped no matter whether JMeter runs successfully or fails.

jmeterRun {
    dependsOn jettyRunWar
    finalizedBy jettyStopWar
}

Try the below settings:

In doFirst()

jettyRunWar.stopPort = 8090
jettyRunWar.stopKey = 'stopKey'

In doLast()

jettyStop.stopPort = 8090
jettyStop.stopKey = 'stopKey'

Not sure if it's a bug related to this Link or that you just need to specify a stopPort for jetty to be listening on.

I was having problems stopping jetty after running the jettyRunWar task in intelliJ but have those 4 settings in my build.gradle allowed me to stop jetty by running the jettyStop task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM