0

I am using TFS 2012 for my build.

When a build runs in TFS, you get given the changesets that were included since the last successful build. These are called Associated Changesets.

I have a custom build activity which I want to fail the build under certain conditions. To trigger this failure, I am simply throwing an exception from it.

The issue I have is that even if the exception is thrown (and the build fails), the next build does not include the changesets in the Associated Changesets from the previous failed build.

Does anyone know at what point in the build workflow the changesets are marked as successful?

The behaviour I am after is that if my custom activity fails the build, the changesets from this build should appear in the Associated Changesets of the next build. And so on, until the build succeeds.

gregpakes
  • 4,465
  • 29
  • 43
  • Does the finished build has failed status? At what point is you error thrown -you may need to ensure that compilation status is failed as well. Check the BuildDefinitions LastBuild LastGoodBuild Uris to see what tfs has recorded there. I have always assumed the changesets are based on the lastgoodbuild version, but it may be that workspace update actually gets the list, see if you have Outputs or None as workspace cleanup setting and try All instead. – drk Aug 05 '13 at 10:31
  • @drk - The build completes with a Failed status. The error is thrown after `If TreatTestFailureAsBuildFailure And (TestStatus = Failed)`. I don't know how to check `LastGoodBuild`. I googled around for it, but couldn't find anything. I think I might need to do something similar to the `If TreatTestFailureAsBuildFailure And (TestStatus = Failed)` condition, which then runs a task called `Set Status to Failed`. – gregpakes Aug 05 '13 at 11:37
  • You may need to use the api for that, this describes how to get build definition object - http://www.almguide.com/2011/11/tfs-api-accessing-build-definition-values-programmatically/. You can also get access to it from BuildDetails that should be available to you in build workflow http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuilddetail.aspx. – drk Aug 05 '13 at 13:29

1 Answers1

0

Instead of throwing an exception use context.TrackBuildError("oops my build broke")

This will cause the build to fail properly and the changesets won't be associated

James Reed
  • 13,873
  • 51
  • 60
  • This is how I had it setup originally and this doesn't work. This causes the build to Partially Succeed rather than fail. The changesets stay associated too. – gregpakes Aug 04 '13 at 06:36
  • Seems that this is the [expected behaviour.](http://stackoverflow.com/questions/6290694/forcing-a-tfs2010-workflow-build-to-fail-instead-of-partially-succeed) – James Reed Aug 04 '13 at 10:32