0

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.

Ben_G
  • 770
  • 2
  • 8
  • 30
  • What's the result if you add "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\" to environment path of the build machine and then call "tfsbuild.exe start" command directly in the post build event? – Eddie Chen - MSFT Jul 31 '17 at 07:45
  • @Eddie - MSFT I tried your suggestion and now I get the error above (I updated my question). – Ben_G Jul 31 '17 at 15:37
  • And @Eddie-MSFT, actually that's how this whole thing started (except that TFSBuild wasn't in the path). I added it and I get the error mentioned above. – Ben_G Jul 31 '17 at 15:51
  • Did you restart the build agent after add the environment path? – Eddie Chen - MSFT Aug 01 '17 at 01:17
  • @Eddie - MSFT - yes I did and now I get no error and the MSBuild log shows it being kicked off, but that doesn't actually happen. Nothing happens (at least by looking at the builds from the project being built's Builds page on Team Explorer (See my update above) – Ben_G Aug 01 '17 at 15:27
  • The build should be queued successfully since the updated build number is returned. Can you find the build with the build number? – Eddie Chen - MSFT Aug 02 '17 at 00:40

2 Answers2

0

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

Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55
  • Thanks @Andy-MSFT, but I wrote a PowerShell script that uses the REST API to kick off the build and I get the same error. I'll update the original question momentarily. – Ben_G Jul 28 '17 at 21:13
  • @Ben_G You can try to add ["exit"](https://stackoverflow.com/questions/2022326/terminating-a-script-in-powershell) for your powershell script to terminate the script, then try it again with "Post-Build script" – Andy Li-MSFT Jul 29 '17 at 07:57
  • I tried adding the Exit to the Powershell script but that didn't help (see the updated issue above). I assume that you were just suggesting that I add "Exit" as the last line of the .ps1 script? – Ben_G Jul 30 '17 at 00:06
0

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

Ben_G
  • 770
  • 2
  • 8
  • 30