gpt4 book ai didi

linux - .net core "dotnet run"命令不会在出错时中断 Azure 构建管道 (bash)

转载 作者:太空宇宙 更新时间:2023-11-04 11:48:01 25 4
gpt4 key购买 nike

使用命令运行 Azure(CentOS 7 客户端)构建管道

# 运行数据库迁移
dotnet 运行 --project $(Build.Repository.LocalPath)/DBMigrations

此作业显示为已成功完成,但出现异常System.Data.SqlClient.SqlException我用过

failOnStderr: true在我的管道配置中。

迁移代码:

sing DbUp;
using System;
using System.Linq;
using System.Reflection;

namespace DBMigrations
{
class Program
{
private const string ConnectionString = "Server=myserver;Database=db;User Id=SA;Password=pass;";

static int Main(string[] args)
{
var connectionString = args.FirstOrDefault() ?? ConnectionString;

EnsureDatabase.For.SqlDatabase(connectionString);

var upgrader =
DeployChanges.To
.SqlDatabase(connectionString)
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
.LogToConsole()
.Build();

var result = upgrader.PerformUpgrade();

if (!result.Successful)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(result.Error);
Console.ResetColor();

return -1;
}

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Success!");
Console.ResetColor();
return 0;
}
}
}

如何在 dotnet run 中使作业因错误而失败?

更新:.net 核心控制台应用程序应写入 Console.ErrorConsole.Error.WriteLine(errorMessage); 使作业失败。 return -1 是不够的。

最佳答案

问题出在

if (!result.Successful)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(result.Error); // <-- here should be Console.Error.WriteLine(result.Error);
Console.ResetColor();

return -1;
}

return -1; 不足以破坏带有 failOnStderr: true

的 Azure bash bild 作业

关于linux - .net core "dotnet run"命令不会在出错时中断 Azure 构建管道 (bash),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56987945/

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