Handling Unexpected Closure of Testing Executions
If a test framework fails or a pipeline stops early, some testing executions can remain open. These open executions can block coverage calculation and leave execution state inaccurate.
Most teams manage cleanup by environment. This is the most common pattern for functional testing, where one environment can host multiple related executions. This page focuses on that use case.
Use the Get Executions Status List API to:
Query executions with
status=created.Filter by
labId.Optionally add
testStage.Close each matching test session.
Details on the Get Executions Status List API are available in the API reference.
Below are sample implementations that query remaining open executions and close them one by one as part of post-run cleanup.
post {
aborted{
echo '[Sealights] Cleanup executions left open.'
withCredentials([string(credentialsId: 'sl.agent.token', variable: 'SL_AGENT_TOKEN')]) {
sh '''
set +x
SL_DOMAIN="yourcustomdomain.sealights.co"
SL_AGENT_TOKEN=$(cat ./sl-agent-token.txt)
SL_LABID="MyLabID"
SL_TESTSTAGE="Functional Tests"
SL_TEST_EXECUTION_IDs=(`curl -sX GET "https://$SL_DOMAIN/sl-api/v1/executions?labId=$SL_LABID&testStage=$SL_TESTSTAGE&status=created" \
-H "Authorization: Bearer $SL_AGENT_TOKEN" \
-H "Content-Type: application/json" \
| jq -r '.data.list | map(.executionId) | join(" ")'`)
# Optional: filter based on Test Stage and/or LabID
echo "Found ${#SL_TEST_EXECUTION_IDs[@]} executions"
for id in ${SL_TEST_EXECUTION_IDs[@]}
do
echo -n "Closing Test Session ID $id: "
curl -isX DELETE "https://$SL_DOMAIN/sl-api/v1/test-sessions/$id" \
-H "Authorization: Bearer $SL_AGENT_TOKEN" \
-H "Content-Type: application/json" | grep HTTP
done
'''
}
}
}GitHub Actions YAML executing the Sealights cleanup step when the Functional Tests job fails or is cancelled.
Python script
Best Practices
URL-encode
testStagevalues that contain spaces or special characters before sending the request.Verify the HTTP status for each
DELETErequest. Treat non-2xxresponses as cleanup failures and log the execution ID for follow-up.If the execution list spans more than one API response, iterate through every page before building
SL_TEST_EXECUTION_IDs. Do not assume a busy shared lab fits in one response.
Last updated
Was this helpful?

