Skip to content

Commit

Permalink
Fixing bug where script output would appear twice in task logs (#1059)
Browse files Browse the repository at this point in the history
Fixing bug where script output would appear twice in task logs
  • Loading branch information
sburmanoctopus authored Jan 23, 2025
1 parent 67b07ca commit 1b68570
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ async Task<ScriptStatus> 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<ScriptOperationExecutionResult> ObserveUntilComplete(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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())
Expand All @@ -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");
}
}
}

0 comments on commit 1b68570

Please sign in to comment.