Extract statistics to print as TeamCity build status

Hi
I am running a gatling simulation from TeamCity and I want to print the final test results in the TeamCity status. To do this I have to access the results at the end of the test and print it to console in a certain way .i.e

log.info(s"##teamcity[buildStatus text='max: ${global.responseTime.max}} | min: ${global.responseTime.min} | mean: ${global.responseTime.mean}")}

Is there any way to do this?
Thanks

I’m not familiar with Teamcity, sorry. You can maybe use the same JSON file used by the Jenkins plugin. Check out result directory content.

Thanks, yeah parsing json is easier than stats.tsv, so I can try to parse it with groovy script and update TeamCity status. Is there any way to know what is the folder name for specific run? For some reason every time I run the simulation it updates all other folders so I can’t check what is the most recent one.

You can either parse the last line displayed in the console or force it with a command line option. See Configuration wiki page.

I ended up with the following groovy script:

@Grab(group=‘com.googlecode.json-simple’, module=‘json-simple’, version=‘1.1.1’)
import org.json.simple.JSONValue

def folder = new File(‘target/gatling/results’).listFiles().sort() {
a,b → a.lastModified().compareTo b.lastModified()
}
def folderPath = folder[0].getAbsolutePath()
println “path to results: ${folderPath[0]}”
def stats = JSONValue.parse(new File("$folderPath/js/global_stats.json").text)

println “##teamcity[buildStatus text=‘requests# ${stats.numberOfRequests.total}| failed:${stats.numberOfRequests.ko}| max:${stats.maxResponseTime.total}| min:${stats.minResponseTime.total}| mean:${stats.meanResponseTime.total}| 95%:${stats.percentiles1.total}| 99%:${stats.percentiles2.total}’]”

Nice!

Yuri, can you please provide steps how to use this groovy script for guys who new to TeamCity?