Azure Web应用程序部署导致VS Team Services中的PowerShell失败

时间:2016-06-13 16:55:05

标签: git powershell azure web azure-devops

我正在使用VS Team Services提供的CI来构建Web应用程序并部署到Azure。它主要使用此处描述的“本地git repo”方法:https://azure.microsoft.com/en-us/documentation/articles/web-sites-publish-source-control/

我使用PowerShell脚本运行部署,如下所示:

$sourcePath = Get-Location
cd ..
mkdir deploy
cd deploy
$deployPath = Get-Location
git init
git config core.safecrlf false
git remote add azure <fill-in>
git pull azure master --quiet
git rm -rf .
git clean -fxd
git reset
Copy-Item $sourcePath\* $deployPath -Recurse
git add -A
git commit -m "Deploy"
git push azure master --porcelain

我注意到几个git操作(如push和pull)会导致PowerShell看到错误(即使操作成功)。这就是我使用“安静”和“瓷器”选项的原因。

现在棘手的部分是,在推送操作之后,Azure将自动运行一些部署脚本。这会导致PowerShell看到错误,即使操作成功,并且......我无法控制它。

如何让PowerShell正确识别真正的错误?

顺便说一句,如果你看到更好或更有效的方式,我会很乐意了解它。

1 个答案:

答案 0 :(得分:1)

尝试使用以下格式调用git命令:

public class Class1
{

}

public class Class2 : Class1
{

}

private void TestType()
{
    var collection = new List<Class1>();
    collection.Add(new Class1());
    collection.Add(new Class2());

    var results = new List<Class1>();

    foreach (var item in collection)
    {
        Class1 c1 = (item as Class1);   // Won't throw if not Class1
        if ( c1 != null )
        {
            results.Add(c1);
        }
    }
}

有关详细信息,请参阅Pascal Berger在此问题中的回答:Visual Studio Online Build treats git output as errors