How to terminate jenkins job , if we are using docker compose command in jenkins file

Context:

I have created docker compose file which creates testproject-agent & chrome container .
Then I created one jenkins file inside my repo, which first creates docker , clones repository and inside docker runs docker compose file which is located inside the repository.

Refer:

stage(‘Install Docker compose’) {
container(‘docker’) {
sh ‘docker --version’
sh ‘apk add docker-compose’
sh ‘ls -ltra’
if(testtype == “after release”) {
sh ‘docker-compose -f docker-compose-tp-after-release.yml up --exit-code-from testproject-agent’
}
else {
sh ‘echo APPLICATION_URL=${application_url} >> .env’
sh ‘docker-compose -f docker-compose-tp-before-release.yml up --exit-code-from testproject-agent’
}
}
}

Problem :
The problem is that even if testproject job fails [due to some reason] , jenkins build job finishes with success status.
Docker compose command makes testproject-agent exit with code 0 , due to which the build is always pass.
Can’t we fetch testproject job status and make jenkins job fail according to the result.

Hi @puniti.chauhan,
If you want to fail the Jenkins job based on the execution result in TestProject you can add the bellow shell script.
the script is first taking the current running execution and then it will take the execution state based on that id and will wait until execution is not still executing or reporting

id=$(curl -X POST "https://api.testproject.io/v2/executions" -H "accept: application/json" -H "Authorization: Your API key")
id=$(echo $id | grep -i id* | awk -F '"' '{print $4}')
stateApi=$(printf "https://api.testproject.io/v2/projects/Your Project ID/jobs/Your Job ID/executions/%s/state" "$id")
state=$(curl -X GET $stateApi -H "accept: application/json" -H "Authorization: Your Api key")
state=$(echo $state | grep -i state* | awk -F '"' '{print $4}')
while [ "$state" == "Executing" ] | ["$state" == "Reporting"]
do
 sleep 5
 state=$(curl -X GET $stateApi -H "accept: application/json" -H "Authorization: Your Api Key")
 state=$(echo $state | grep -i state* | awk -F '"' '{print $4}')
done

{
Make if statement, if $state parameter equals passed exist code 0 else use exit code 1 to fail Jenkins job
}

The script is using TestProject API which can also build your curl command.
You can follow this TestProject API v2

If you do the check after the execution of the docker agent has already finished you can just add a validation after by using this API call TestProject API v2 and extract the result of the execution from this and exit according to the extracted value of passed or failed.

Please let me know if you manage to implement this.