Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing bug where script output would appear twice in task logs #1059

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
}