[英].net core “dotnet run” command don't breake Azure buid pipeline (bash) on error
Running an Azure (CentOS 7 client) build pipeline with a command 使用命令运行Azure(CentOS 7客户端)构建管道
# Run DB migrations dotnet run --project $(Build.Repository.LocalPath)/DBMigrations
this job is shown as completed successfully, although there was an exception System.Data.SqlClient.SqlException
and I used 尽管存在
System.Data.SqlClient.SqlException
异常,但我使用了该作业,但该作业显示为成功完成
failOnStderr: true
in my pipeline configuration. failOnStderr: true
在我的管道配置中为failOnStderr: true
。
Migrations code: 迁移代码:
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;
}
}
}
How can I make a job fail on error in dotnet run? 如何使作业因dotnet运行中的错误而失败?
Update: .net core console application should write to Console.Error Console.Error.WriteLine(errorMessage);
更新: .net核心控制台应用程序应写入Console.Error
Console.Error.WriteLine(errorMessage);
to fail a job. 失业
return -1
is not enough. return -1
是不够的。
The problem was in 问题出在
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;
is not enought to break an Azure bash bild job with failOnStderr: true
不足以使用
failOnStderr: true
中断Azure bash bild作业failOnStderr: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.