diff --git a/source/Octopus.Tentacle.Client/Scripts/ObservingScriptOrchestrator.cs b/source/Octopus.Tentacle.Client/Scripts/ObservingScriptOrchestrator.cs index 4aa6882aa..2f63295cd 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, we need 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"); } } }