From f1ba8deffd712d431510ed68aff00377ee8f117d Mon Sep 17 00:00:00 2001 From: "Matthew Parker [SSW]" <61717342+MattParkerDev@users.noreply.github.com> Date: Sun, 13 Oct 2024 23:23:43 +1000 Subject: [PATCH] update exit code --- .../Host/PipelineApplication.cs | 5 ++++ .../ParallelPipelines.csproj | 4 +++ .../OrchestratorServiceTests.cs | 27 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/ParallelPipelines/Host/PipelineApplication.cs b/src/ParallelPipelines/Host/PipelineApplication.cs index 761c7d1..efc764c 100644 --- a/src/ParallelPipelines/Host/PipelineApplication.cs +++ b/src/ParallelPipelines/Host/PipelineApplication.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using Microsoft.Extensions.Hosting; +using ParallelPipelines.Domain.Enums; using ParallelPipelines.Host.Services; using Spectre.Console; @@ -21,6 +22,10 @@ public async Task StartAsync(CancellationToken cancellationToken) { var pipelineSummary = await _orchestratorService.RunPipeline(cancellationToken); await _postStepService.RunPostSteps(pipelineSummary, cancellationToken); + if (pipelineSummary.OverallCompletionType is CompletionType.Cancelled or CompletionType.Failure) + { + Environment.ExitCode = 1; + } } catch (Exception e) { diff --git a/src/ParallelPipelines/ParallelPipelines.csproj b/src/ParallelPipelines/ParallelPipelines.csproj index fc565fa..4a76a89 100644 --- a/src/ParallelPipelines/ParallelPipelines.csproj +++ b/src/ParallelPipelines/ParallelPipelines.csproj @@ -27,4 +27,8 @@ + + + + diff --git a/tests/ParallelPipelines.Unit.Tests/OrchestratorServiceTests.cs b/tests/ParallelPipelines.Unit.Tests/OrchestratorServiceTests.cs index 9bef8c6..dbd8dea 100644 --- a/tests/ParallelPipelines.Unit.Tests/OrchestratorServiceTests.cs +++ b/tests/ParallelPipelines.Unit.Tests/OrchestratorServiceTests.cs @@ -1,9 +1,11 @@ +using System.Diagnostics; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Example.Deploy.Steps._1Setup; using ParallelPipelines.Domain.Enums; using ParallelPipelines.Host; +using ParallelPipelines.Host.Helpers; using ParallelPipelines.Host.Services; using ParallelPipelines.Unit.Tests.TestSteps; using Spectre.Console; @@ -116,4 +118,29 @@ public async Task OrchestratorService_TestTimings() pipelineSummary?.DeploymentEndTime.Should().BeCloseTo(step4.EndTime!.Value, TimeSpan.FromMilliseconds(10)); } + + [Fact] + public async Task ParallelPipelinesApplication_FailedStep_ExitsWithExitCode1() + { + // To pass, add a throw in one of the steps + var cts = new CancellationTokenSource(); + await PipelineFileHelper.PopulateGitRootDirectory(cts.Token); + // new process + var process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = "dotnet", + Arguments = "run", + WorkingDirectory = Path.Combine(PipelineFileHelper.GitRootDirectory.FullName, "examplesrc/Example.Deploy"), + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + } + }; + process.Start(); + await process.WaitForExitAsync(); + process.ExitCode.Should().Be(1); + } }