【问题标题】:Visual Studio Team Services says "Task PowerShell failed" although it didn'tVisual Studio Team Services 说“任务 PowerShell 失败”,尽管它没有
【发布时间】:2015-07-17 08:18:39
【问题描述】:

我在 VS Team Services 中的 powershell 脚本末尾收到以下错误:

任务 PowerShell 失败。这导致作业失败。查看任务的日志以了解更多详细信息。

但是,脚本并没有失败。它做了我想做的一切。有什么方法可以向 VS Team Services 解释吗?

该脚本从 VS Team Services 获取已编译和测试的代码,并将其推送到 bitbucket 上的 git 存储库。这样,我可以从它自动创建一个 docker 容器并更新我的应用程序。这是脚本:

git clone BITBUCKET_URL/example-repo.git
cd example-repo

echo "Clean app-folder and remove Dockerfile"

remove-item app -recurse -force
remove-item Dockerfile -force

new-item -name app -itemtype directory

echo "Copy new files into repository"

cp ../deploy/Dockerfile .
cp ../ExampleApp/bin/Debug/* ./app

echo "Set email, name and include all files"

git config user.email "EMAIL"
git config user.name "NAME"
git add -A

echo "What has changed:"
git status

echo "Commit and Push..."
git commit -m "VS Online Commit"
git push origin master

此脚本运行并正确执行所有操作。但是,我的 Visual Studio Team Services 日志到此结束:

******************************************************************************
Starting task: Powershell: deploy/deploy.ps1
******************************************************************************
Cloning into 'example-repo'...
Clean app-folder and remove Dockerfile
    Directory: C:\PROJECT\example-repo
Mode                LastWriteTime     Length Name                                                                      
----                -------------     ------ ----                                                                      
d----         7/17/2015   7:59 AM            app                                                                       
Copy new files into repository
Set email, name and include all files
What has changed:
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
    modified:   app/App.exe
    modified:   app/App.pdb
Commit and Push...
 VS Online Commit
 2 files changed, 0 insertions(+), 0 deletions(-)
To BITBUCKET_URL/example-repo.git
b861c96..afd33e6 master -> master
******************************************************************************
Finishing task: PowerShell
******************************************************************************
Task PowerShell failed. This caused the job to fail. Look at the logs for the task for more details.
******************************************************************************
Finishing Build
******************************************************************************

从此输出中,以下几行是红色的,类似于错误行:

Cloning into 'example-repo'...

To BITBUCKET_URL/example-repo.git
b861c96..afd33e6 master -> master

难道这里的某些东西返回的不是 0,这就是 VS Team Services “检测”失败的原因?

我怎样才能防止这种情况发生?

更新:

仅运行 git clone 已经表明存在错误,因此 git clonegit push 似乎确实会导致 VS Team Services 将其视为错误。

【问题讨论】:

    标签: git powershell continuous-integration azure-devops


    【解决方案1】:

    正如Vesper 在他的回答中所写,git 正在向 stderr 发送输出,而 VS Team Services 认为它​​因此而失败。

    但是,仅重定向或忽略 stderr 对我来说似乎不是正确的解决方案。相反,您可以指定:

    git clone --quiet ...
    git push --porcelain ...
    

    阻止 git 报告 stderr 上的状态并完全停止报告 (--quiet) 或将其发送到 stdout (--porcelain)。

    更新:

    如果git add 显示有关行尾的警告,您可以使用以下配置禁用它:

    git config core.safecrlf false
    

    当然,您可能还想在配置中设置core.autocrlf

    【讨论】:

    • 知道一个命令的参数确实比一个通用的解决方案要好。如果可能的话,当然可以。 :)
    【解决方案2】:

    显然,Visual Studio 对错误通道的反应就像脚本出错一样。由于您的git 将一些输出发送到错误通道,因此您可以将脚本与2&gt;&amp;1 输出重定向器一起使用,或者在脚本中将$ErrorActionPreference 设置为silentlyContinue,或者以相同的方式重定向所有git 命令输出@987654326 @。

    关于退出代码 - 如果您的脚本不包含 exit &lt;code&gt; 命令,则其退出代码为零,因为所有 git 命令的退出代码都被 Powershell 在解释脚本时吸收,在脚本右侧可用在每个命令之后为$lastExitCode,但如果不使用则丢弃。

    【讨论】:

    • 感谢提示。我没有设法使用2&gt;&amp;1 但是,我想这比我最终提出的解决方案更像是一种解决方法
    猜你喜欢
    • 2017-05-25
    • 2016-08-16
    • 2017-11-26
    • 2016-05-13
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多