使用命令运行Azure(CentOS 7客户端)构建管道
# Run DB migrations
dotnet run --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运行中的错误而失败?
更新:
.net核心控制台应用程序应写入Console.Error
Console.Error.WriteLine(errorMessage);
失业。 return -1
是不够的。
答案 0 :(得分:0)
问题出在
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作业