From 29895494d88dc0646a80ca57aedb83b720f69774 Mon Sep 17 00:00:00 2001 From: Stephen Burman Date: Thu, 23 Jan 2025 15:21:22 +1100 Subject: [PATCH 1/2] Fixing bug where script output would appear twice in task logs --- .../Scripts/ObservingScriptOrchestrator.cs | 12 ++++++++---- .../ClientScriptExecutionAdditionalScripts.cs | 8 ++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/source/Octopus.Tentacle.Client/Scripts/ObservingScriptOrchestrator.cs b/source/Octopus.Tentacle.Client/Scripts/ObservingScriptOrchestrator.cs index 4aa6882aa..058240263 100644 --- a/source/Octopus.Tentacle.Client/Scripts/ObservingScriptOrchestrator.cs +++ b/source/Octopus.Tentacle.Client/Scripts/ObservingScriptOrchestrator.cs @@ -57,10 +57,14 @@ async Task ObserveUntilCompleteThenFinish( // V1 can return a result when completing. But other versions do not. // The behaviour we are maintaining is that the result to use for V1 is that of "complete" // but the result to use for other versions is the last observing result. - var scriptStatusResponse = completeScriptResponse ?? observingUntilCompleteResult.ScriptStatus; - OnScriptStatusResponseReceived(scriptStatusResponse); - - return scriptStatusResponse; + if (completeScriptResponse is not null) + { + // Because V1 can actually return a result, needs to handle the response received as well (so the output appears in Octopus Server) + OnScriptStatusResponseReceived(completeScriptResponse); + return completeScriptResponse; + } + + return observingUntilCompleteResult.ScriptStatus; } async Task ObserveUntilComplete( diff --git a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionAdditionalScripts.cs b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionAdditionalScripts.cs index 24e6ea8ca..3f457c447 100644 --- a/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionAdditionalScripts.cs +++ b/source/Octopus.Tentacle.Tests.Integration/ClientScriptExecutionAdditionalScripts.cs @@ -18,6 +18,7 @@ public class ClientScriptExecutionAdditionalScripts : IntegrationTest [TentacleConfigurations(testCommonVersions: true)] public async Task AdditionalScriptsWork(TentacleConfigurationTestCase tentacleConfigurationTestCase) { + const string printOutput = "Hello"; using var tmp = new TemporaryDirectory(); var path = Path.Combine(tmp.DirectoryPath, "file"); @@ -26,7 +27,7 @@ public async Task AdditionalScriptsWork(TentacleConfigurationTestCase tentacleCo var scriptBuilder = new ScriptBuilder() .CreateFile(path) // How files are made are different in bash and powershell, doing this ensures the client and tentacle really are using the correct script. - .Print("Hello"); + .Print(printOutput); var startScriptCommand = new TestExecuteShellScriptCommandBuilder() .WithAdditionalScriptType(ScriptType.Bash, scriptBuilder.BuildBashScript()) @@ -44,7 +45,10 @@ public async Task AdditionalScriptsWork(TentacleConfigurationTestCase tentacleCo var allLogs = logs.JoinLogs(); - allLogs.Should().Contain("Hello"); + allLogs.Should().Contain(printOutput); + allLogs.IndexOf(printOutput, StringComparison.OrdinalIgnoreCase) + .Should() + .Be(allLogs.LastIndexOf(printOutput, StringComparison.OrdinalIgnoreCase), because: "We should not repeat the script output"); } } } From 1e96106caa6af20d68daa548d85865b4d70a6285 Mon Sep 17 00:00:00 2001 From: Stephen Burman Date: Thu, 23 Jan 2025 15:29:28 +1100 Subject: [PATCH 2/2] Comment was off --- .../Scripts/ObservingScriptOrchestrator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Octopus.Tentacle.Client/Scripts/ObservingScriptOrchestrator.cs b/source/Octopus.Tentacle.Client/Scripts/ObservingScriptOrchestrator.cs index 058240263..2f63295cd 100644 --- a/source/Octopus.Tentacle.Client/Scripts/ObservingScriptOrchestrator.cs +++ b/source/Octopus.Tentacle.Client/Scripts/ObservingScriptOrchestrator.cs @@ -59,7 +59,7 @@ async Task ObserveUntilCompleteThenFinish( // but the result to use for other versions is the last observing result. if (completeScriptResponse is not null) { - // Because V1 can actually return a result, needs to handle the response received as well (so the output appears in Octopus Server) + // Because V1 can actually return a result, we need to handle the response received as well (so the output appears in Octopus Server) OnScriptStatusResponseReceived(completeScriptResponse); return completeScriptResponse; }