TeamCity job, run step only if a previous one has failed?

Theres no way to setup a step to execute only if a previous one failed.

The closest I've seen to this, is to setup a build that has a "Finish Build" trigger that would always execute after your first build finishes. (Regardless of success or failure).

Then in that second build, you could use the TeamCity REST API to determine if the last execution from the first build was successful or not. If it wasn't successful then you could whatever it is you want to do.


As a work around it is possible to set a variable via a command line step that only runs on success which can be checked later.

enter image description here

echo "##teamcity[setParameter name='env.BUILD_STATUS' value='SUCCESS']"

This can then be queried inside a powershell step that is set to run even if a step fails.

enter image description here

if($env:BUILD_STATUS -ne "SUCCESS"){

}

Tags:

Teamcity