git – Visual Studio Team Services说“Task PowerShell失败了.”虽然它没有

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

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

但是,脚本没有失败,它完成了我想要它做的一切.有什么方法可以向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 clone和git push会导致某些被VS Team Services视为错误的事情.

最佳答案 显然,Visual Studio会对错误通道做出反应,就像脚本出错了一样.由于您的git将一些输出发送到错误通道,您可以使用带有2>& 1输出重定向器的脚本,或者将$ErrorActionPreference设置为脚本中的silentntlyContinue,或者以相同的方式重定向所有git命令输出2>& 1.

关于退出代码 – 如果您的脚本不包含退出< code>命令,其退出代码为零,因为所有git命令的退出代码在解释脚本时被Powershell吸收,在每个命令之后的脚本中可用作$lastExitCode,但如果不使用则丢弃.

点赞