gpt4 book ai didi

powershell - 当错误写入错误流时,如何防止 TFS 使 PowerShell 步骤失败?

转载 作者:行者123 更新时间:2023-12-02 22:37:34 25 4
gpt4 key购买 nike

我在 TFS 构建中有一个 PowerShell 步骤,该步骤将错误写入错误流,从而导致构建失败。我希望该步骤忽略错误并继续成功。

Process completed with exit code 0 and had 1 error(s) written to the error stream.

我尝试在 TFS 中设置出错时继续选项,但这会导致“构建部分成功”状态,但我想要的是它“成功”。

我还尝试将 2>&1 > output.txt 添加到生成错误的行末尾,但错误仍然写入 TFS 输出,而不是在文本中捕获文件。

我正在执行的命令是 TFS 2015 Power Tools 中的 New-TfsChangeset cmdlet。

最佳答案

您可以在 PowerShell 脚本配置中取消选中“标准错误失败”,并编写 Lastexitcode 来传递任务。

Enter image description here

Fail on Standard Error

If this is true, this task will fail if any errors are written to the error pipeline, or if any data is written to the Standard Error stream. Otherwise the task will rely solely on $LASTEXITCODE and the exit code to determine failure.

然后您可以使用 PowerShell 或 VSTS 任务命令输出错误或警告。

Write-Warning “warning”
Write-Error “error”
Write-Host " ##vso[task.logissue type=warning;]this is the warning"
Write-Host " ##vso[task.logissue type=error;sourcepath=consoleapp/main.cs;linenumber=1;columnnumber=1;code=100;]this is an error "

更多关于VSTS任务命令的信息,可以引用:Logging Commands

关于powershell - 当错误写入错误流时,如何防止 TFS 使 PowerShell 步骤失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44560280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com