TFS Build PowerShell步骤中的Robocopy报告失败但没有错误 [英] Robocopy in TFS Build PowerShell Step Reports Failure But Has No Error

查看:105
本文介绍了TFS Build PowerShell步骤中的Robocopy报告失败但没有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的powershell脚本在运行时没有在日志文件中报告错误,但是TFS 2015构建步骤报告了错误.我需要执行特殊的回叫吗?

My powershell script runs without error reported in the log file, but the TFS 2015 build step reports an error. Do I need to perform a special call back?

这是一种新样式,而不是基于XAML的样式.

This is a new style build, not a XAML based one.

该脚本没什么特别的,它调用robocopy,成功完成.

The script is nothing special, it calls robocopy, which occurs successfully.

这是脚本:

[CmdletBinding()]
param (
  [string]$localWorkspace,
  [string]$destination 
)
begin{}
process
{
  try
  {
    ## Script
    $ServiceDirs = Get-ChildItem $localWorkspace -Recurse | ?{ $_.PSIsContainer -eq $True -and $_.Name -match "^Service$" } | % { $_.FullName }

    $serviceCollection = @{}
    foreach ($Service in $ServiceDirs)
    {
      $ServiceName = Get-ChildItem $Service | ?{$_.Name -match ".*\.csproj$" } | % { $_.BaseName }

      $binpath = ($service + "\bin\release")
      $serviceCollection.Add($serviceName , $binpath)
    }

    $serviceCollection.GetEnumerator() | % { 
      Write-Verbose "Processing service: $($_.key)" 

      $currentDestination = ($destination + "\" + $_.key)
      $output = robocopy $_.value $currentDestination /MIR /NFL /NDL /NJH /NJS /nc /ns /np
    }
  }
  catch
  {
    write-host "Caught an exception:" 
    write-host "Exception Type: $($_.Exception.GetType().FullName)" 
    write-host "Exception Message: $($_.Exception.Message)" 
  }
}
end{}

如果我取消沉默,并使用/DEBUG,并且在TFS构建日志中没有任何捕获,则可以看到所有robocopy输出.

I can see all the robocopy output, if I unsilence it and use /DEBUG and none of the catch in the TFS build log.

奇怪的是,当我强制执行错误时,捕获执行并且该步骤报告成功.

Strangely, when I force an error, the catch executes and the step reports success.

报告的错误消息是:

任务PowerShell失败.这导致作业失败.看日志 有关该任务的更多详细信息.

Task PowerShell failed. This caused the job to fail. Look at the logs for the task for more details.

推荐答案

TL; DR 检查呼叫中使用的退出代码,或使用exit离开 脚本.


RoboCopy 使用一套退出代码,包括:

TL;DR Check the exit codes used in the calls, or use exit to leave the script.


RoboCopy uses a suite of exit codes including:

0×00 0没有错误发生,并且没有完成复制. 源目录树和目标目录树是完全同步的.

0×00 0 No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.

0×01 1成功复制了一个或多个文件(即,新文件已到达).

0×01 1 One or more files were copied successfully (that is, new files have arrived).

(完整列表在这里)

因为脚本没有exit语句,所以$LastExitCode的值为1,这对于Robocopy有意义,但会导致TFS认为脚本失败.

Because the script didn't have an exit statement the value of $LastExitCode was 1 which makes sense for Robocopy but causes TFS to believe the script to fail.

使用exit禁止了Robocopy退出代码,因此TFS认为该脚本有效.但是,这意味着所有Robocopy信息都被压制了.

Using exit supressed the Robocopy exit code so TFS believed the script to have worked. However, this meant that any Robocopy information was being suppressed.

根据本文,将最后一行更改为exit ($LastExitCode -band 24)可以正确解决该问题.

Changing the final line to exit ($LastExitCode -band 24) solved the issue properly, as per this article.

这篇关于TFS Build PowerShell步骤中的Robocopy报告失败但没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆