簡體   English   中英

.net核心“ dotnet運行”命令不會在出現錯誤時中斷Azure buid管道(bash)

[英].net core “dotnet run” command don't breake Azure buid pipeline (bash) on error

使用命令運行Azure(CentOS 7客戶端)構建管道

# Run DB migrations dotnet run --project $(Build.Repository.LocalPath)/DBMigrations

盡管存在System.Data.SqlClient.SqlException異常,但我使用了該作業,但該作業顯示為成功完成

failOnStderr: true在我的管道配置中為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是不夠的。

問題出在

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作業failOnStderr: true

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM