Error code 255 when trying to kick off a TFS2013 team build via a PostBuildEvent

1.5k views Asked by At

I'm trying to kick off a team build when another team build finishes, so I've added this to the .csproj of the project being built:

<PropertyGroup Condition=" $(IsDesktopBuild) == 'false' ">
<PostBuildEvent>
  <command>
    cmd /c "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tfsbuild.exe" start /collection:http://Server/CollectionName /builddefinition:\BuildDefinitionName
  </command>
</PostBuildEvent>

I've tried it without the cmd /c and that doesn't help. I also tried it without the command /command around it, but I get the same error no matter which option I choose. If I simply copy and paste the command into a DOS window it works fine. The error is:

C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (4548): The command "<command xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    cmd /c "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tfsbuild.exe" start /collection:Server/Collection /builddefinition:\BuildDefinitionName
  </command>" exited with code 255.

I took @Andy-MSFT's advice and wrote a powershell script to do a REST call to the server and I get the same result:

enter image description here

Here's the call to the script: enter image description here

Here's the PowerShell script I wrote: enter image description here

When I run the script from the command line it works fine. And I can run it twice in succession, so it's not a case of not being able to run it while a build is running.

Update 7/29/17

I took @Andy-MSFT's latest advice and added an exit as the last line of the PowerShell script and I still get this error:

Notice the command at the end of the error message, so I took out the command /command xml and now I get this:

The error changed from a 255 to a 123. Any ideas what that means?

UPDATE 7/31/17 @Eddie - MSFT I added tfsbuild to the PostBuildEvent as you suggested and I get this:

Here's what my PostBuildEvent looks like:

UPDATE 2 - 1/31/17 to @Andy-MSFT & @Eddie - MSFT I got the initial build to run using the following AfterBuild target, but it doesn't actually do anything (it doesn't kick off the build). There's no mention of it in the log either:

Update 3 - 7/31/17 I tried adding some debugging info to my powershell script (see below), so I write to a text file when the script starts and again I try to write the result of the call to kick off the build. In all cases it writes the first file so I know that the script is starting. If I run it from the command-line the file result.txt is full of text from the resulting build, but when run from the AfterBuild target the file is empty. Not sure if that helps, but I thought it was relevant:

UPDATE 8/1/17 in response to the latest comment by @Eddie - MSFT

Yes - I tried that. It builds, but the call doesn't seem to work. No error messages, but no build kicked off. Here's the call:

enter image description here

And here's the log that shows it presumably being kicked off, but it is not:

UPDATE 8/1/17 8:51am PT I got the build to appear to kick off (I captured the result from the call in my PowerShell script and wrote it to a file here, but the build still doesn't actually get kicked off.

2

There are 2 answers

0
Ben_G On BEST ANSWER

I have no idea why, but this just started working. I appended "http://" to the beginning of the GetServer() call, but I don't think that's what made it work. Anyway, it works now. Thanks @Andy-MSFT and @Eddie @ MSFT for your help with this!

enter image description here

3
Andy Li-MSFT On

I can reproduce this issue, the reason is you can not start another build within the build processing. That means you can use the command to start a new build after the previous one is completed. You can check this by running the command when a build is running, it will receive the error accordingly.

So, we can not use the PostBuildEvent or Post-Build script to achieve that.

You can try to use the REST API to request a new build, it will queue the builds.

enter image description here