How to Pass simulation state to Jenkins

Hi Gatling Experts.

I have process, that executes Automation tests and stores the results in wiremock (mockServer).
Jenkins starts another process, that should create report as html and according to the results,should return true or false(in case of failure exists)
to Jenkins.

I tried to do something like example below ,but simulation always succeeded .How can I return to Jenkins FALSE when I need.

Thanks for advance.

val getData =
exec(http(“get data from wiremock”)
.post("/__admin/requests/find")
.body(StringBody("""{ “urlPattern” : “/report/.*”,“method” : “POST” }"""))
.check(jsonPath("""$.requests""").saveAs(“lastReports”)))

val handleReportCreation = group(“Create Report”) {
exec(getData)
.exec(session => {
session
.set(“status”, new ReportHandler(session(“lastReports”).as[String]).createReport()) // should return true or false(in case of failure exists)
.apply(session)
})
.exec(session =>{
println("STATUS = "+session(“status”).as[Boolean])
session
})
.doIf(session=> session(“status”).as[Boolean] == false) {
exec(session => session.markAsFailed).exitHereIfFailed

}

}

val createreport = scenario(“Create Automation Tests Report”).exec(handleReportCreation)

setUp(createreport.inject(atOnceUsers(1)).protocols(httpProtocol))

I forgot to mention :
I use Gatling 1.2.4

I saw correspondence about same issue at :
https://groups.google.com/forum/#!searchin/gatling/session.markAsFailed/gatling/MQG8nFgB8RE/-cRJvjN_q-IJ

Maybe I do something wrong ? Or this feature still didn’t implemented ?

In order to have Gatling return a non 0 status call to the launcher (CLI, maven plugin, etc) is to use assertions.

Thanks for quick response.
I will try.

Stephane is it exists any way to assert session variable value via DSL?
In my example assertion of Boolean variable.

Thanks for advance.

Assertions only work on requests. The only way is see is to have some kind of dummy request, with a check that fails if your boolean is false, and some assertion on this sole request.

Ok.
Thanks.
Good idea.
But don’t you think that this is good use case for addition such a feature to gatling assertions handling.

Stephane hi.

I did something like you suggested, but something is wrong.I get error in runtime “Could not find stats matching assertion path List(assertion) : false

this is my code.Can you please tell me why it doesn’t work
.
.
.

val getData =
exec(http(“get data from wiremock”)
.post("/__admin/requests/find")
.body(StringBody("""{ “urlPattern” : “/report/.*”,“method” : “POST” }"""))
.check(jsonPath("""$.requests""").saveAs(“lastReports”)))

def assertion(state: String) = {
doIfEqualsOrElse(state, “”“false”"") {
exec(http("Dummy Request For Success ")
.post("/check/assertion") //Post request responses with 200 status code
.body(StringBody(state))
.check(status.is(200)))
} {

exec(http(“Dummy Request For Failed Assertion”)
.put("/check/assertion") //Put request responses with 400 status code
.body(StringBody(state))
.check(status.is(400)))
}
}

val handleReportCreation = group(“Create Report”) {
exec(getData)
.exec(session => {
session
.set(“isTestFailed”, new ReportHandler(session(“lastReports”).as[String]).createReport())
.apply(session)
})
.exec(session => {
println("isTestFailed = " + session(“isTestFailed”).as[Boolean])
session
})
.doIfOrElse("${isTestFailed}") {
exec(assertion(“true”))
} {

exec(assertion(“false”))
}
}

val createreport = scenario(“Create Automation Tests Report”).exec(handleReportCreation)

setUp(createreport.inject(atOnceUsers(1)).protocols(httpProtocol)).assertions(details(“assertion”).failedRequests.percent.is(0))
.
.
.

I really don’t see any easy way to have assertion conditions computed after the run with the current implementation.
Assertions are serialized at the beginning of the run, so they’re available from the stats generation phase that comes later.