One of our requirements is to wait till the TFS build which is queued is completed and then we need to perform next task, I have written the below code to achieve this but this isn't giving me the desired results.
function Wait-QueuedBuild ()
{
$serverName="http://tfs001:8080/tfs/Collection"
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
$buildserver = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$build = $buildServer.QueueBuild($buildServer.GetBuildDefinition("CollectionUtility\BUILD_FULL",$_.Name))
do
{
sleep 1
}
while (!(build.Status -eq 'InProgress'))
}
You need to keep querying the build status in the loop just as Andrey mentioned. The code should like:
do {
sleep 1;
$queryoption = [Microsoft.TeamFoundation.Build.Client.QueryOptions]::All;
$build = $buildserver.GetQueuedBuild($build.Id,$queryoption);
}
while ($build.Status -eq 'InProgress')