We're using TeamCity 7 and wondered if it's possible to have a step run only if a previous one has failed? Our options in the build step configuration give you the choice to execute only if all steps were successful, even if a step failed, or always run it.
Is there a means to execute a step only if a previous one failed?
Another build failure condition causes TeamCity to mark build as failed when a certain text is present in the build log. To add such failure condition, click Add build failure condition and select from the list: Fail build on metric change.
In Build Steps, click Auto-detect build steps, and then select the proposed steps you want to add to the current build configuration. You can change their settings afterwards. When scanning the repository, TeamCity progressively searches for project files on the two highest levels of the source tree.
Navigate to the Overview tab of the Build Results page (or the Current Problems tab of the Project Home), click the arrow next to the build problem, and then click Investigate/Mute.
To run a custom build with specific changes, open the build results page, go to the Changes tab, expand the required change, click the Run build with this change, and proceed with the options in the Run Custom Build dialog. Use HTTP request or REST API request to TeamCity to trigger a build.
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.
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.
if($env:BUILD_STATUS -ne "SUCCESS"){
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With