【发布时间】:2015-11-27 05:39:13
【问题描述】:
我的 powershell 脚本运行时没有在日志文件中报告错误,但 TFS 2015 构建步骤报告了错误。我需要执行特殊的回调吗?
这是一种新风格的构建,而不是基于 XAML 的构建。
脚本没什么特别的,调用robocopy,成功发生。
这是脚本:
[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 输出。
奇怪的是,当我强制出错时,catch 会执行并且 step 报告成功。
报错信息为:
任务 PowerShell 失败。这导致作业失败。看日志 了解更多详情。
【问题讨论】:
标签: powershell tfs azure-devops tfs-2015 robocopy