How can I cancel build from Task in TFSBuild.proj?

279 views Asked by At

I have a trigger to build projects on check-ins. But I want to add some check and cancel build in some cases.

I created a Task with condition I want to check. I can run this task using TFSBuild.proj file with code like this where CheckIfBuildNeeded is the name of my Task:

<Target Name="BeforeCompile">
  <CheckIfBuildNeeded>
    .....
  </CheckIfBuildNeeded>
</Target>

So, the answer is, how can I cancel/stop build from Task's Execute() method or any other place? How can I get the Build object?

I know I can get builds from TFS with this code. But to do something with build I, naturally, need to know it's ID.

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://foo.bar/tfs");
IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
1

There are 1 answers

0
Christopher Painter On

Take a look at the Error Task.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="ValidateCommandLine">
        <Error
            Text=" The 0 property must be set on the command line."
            Condition="'$(0)' == ''" />
        <Error
            Text="The FREEBUILD property must be set on the command line."
            Condition="'$(FREEBUILD)' == ''" />
    </Target>
    ...
</Project>