9

I currently have a custom workflow activity to run an external process, after the solution has been compiled successfully, that returns an ExitCode <> 0 if the external process has failed. Once I know that the process has failed, I want to set the build status to FAIL (as you would see if code has not compiled) so I have added a SetBuildProperties activity which will set the Status property to BuildStatus.Failed but this only seems to result in giving a Partially Succeeded build when the build is finished.

I have tried setting the build's compilation status to failed inside my custom activity which does result in a Failed build, but I don't really want to have to do that as it is misleading when the solution has compiled.

Can anyone tell me how I can force a build to fail?? (preferably without having to set the compilation status to failed!)

Thanks

Vermin
  • 917
  • 2
  • 11
  • 23
  • ps, I initially followed Ewalf Hofman's guide to faile a build from a console application, but this guide only results in a Partially Successful build – Vermin Jun 09 '11 at 09:52
  • Well if you want the compilation status to be succesfull you'll always get a partially succeeded build as the compilation has succeeded but something else failed, so this makes the build partially succeed – thekip Jun 09 '11 at 19:05

2 Answers2

4

What happened here is that when the build finishes, the workflow manager will overwrite the build status to a value that depends on the combination of statuses of the build process. In your case, the CompilationStatus is Succeeded, but there is a custom activity failure (you set the BuildStatus to Failed), so the overall status would be PartiallySucceeded.

The only workaround here is to set the CompilationStatus to either Failed or Unknown, then the build status will be Failed.

I haven't tried setting the CompilationStatus to Unknown though. But if it can be done, you can later go back and change it to Passed. Just a way to distinguish with the real failed compilation builds.

Not a great workaround, I know :(

UPDATE: Using SetBuildProperties activity to set the build status to Failed and I was able to fail the build even though the compilation succeeded.

Duat Le
  • 3,586
  • 2
  • 19
  • 18
  • Just looked at the source code. It could potentially be a bug in our code that we don't respect the status setting. I'll reply back with more details after trying to repro this myself. If it is we'll fix it in the next release. Thanks for finding it. – Duat Le Jun 09 '11 at 20:10
  • thanks for your answer. shame I can't get it to work in the desired way, but I'm pretty chuffed I've found a bug in TFS lol – Vermin Jun 10 '11 at 10:45
  • I've now tried setting the compilation status to unknown, and this results in a partially succeeded build. To get the build to fail outright, I had to set the compilation status to failed. – Vermin Jun 14 '11 at 11:58
  • Interesting - Sorry I've been too busy lately but I'll set out to repro this very soon in the next couple of weeks. Sorry for the inconvenience. – Duat Le Jun 14 '11 at 14:48
  • Hey Vermin - I modified the default template to add a SetBuildProperties activity at the end to set the build status to Failed and the build actually failed regardless the compilation status. Just thought to let you know. You probably set the build status in your custom activity? If you want me to try the way you did it would you mind sharing the setting build status code? – Duat Le Jun 28 '11 at 00:55
  • Update: I finally tried a custom activity that set the build status to Failed and it worked fine. You might have missed something. – Duat Le Jul 16 '11 at 01:32
1

In TFS 2013, using a customized build template you can just set the the build status to Failed while leaving the CompilationStatus and TestStatus to it's rightful values. You have to do it after the test run though, otherwise it gets updated back. Use the SetBuildProperties activity and set the "Status" property.

Jessica
  • 23
  • 5