Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

teamcity

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?

like image 625
larryq Avatar asked Oct 30 '13 16:10

larryq


People also ask

How do you mark as failed in TeamCity?

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.

How do you edit building steps in TeamCity?

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.

How do you mute a TeamCity test?

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.

How do you run builds in TeamCity?

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.


2 Answers

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.

like image 119
Welsh Avatar answered Oct 18 '22 23:10

Welsh


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"){

}
like image 40
John Avatar answered Oct 18 '22 23:10

John