Skip to content

Commit

Permalink
Propagate exit code from child bash if it fails (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
APErebus authored Dec 4, 2023
1 parent 4c5f233 commit a3a2b22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 7 additions & 1 deletion source/Octopus.Tentacle/Kubernetes/bootstrapRunner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ cd "$WORK_DIR" || return

/bin/bash "$BOOTSTRAP_SCRIPT" "$@"

#Get the return value from the previous script
RETURN_VAL=$?

# Write a message to say the job has completed
echo "##octopus[stdout-verbose]"
echo "Kubernetes Job completed"
echo "##octopus[stdout-default]"

# This ungodly hack is to stop the pod from being killed before the last log has been flushed
sleep 0.250 #250ms
sleep 0.250 #250ms

#Propagate the return value from the bootstrap script to the output host
exit "$RETURN_VAL"
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ await jobService.Watch(scriptTicket, job =>
return resultStatusCode;
}



async Task CreateJob(IScriptLogWriter writer, CancellationToken cancellationToken)
{
//write the bootstrap runner script to the workspace
Expand Down Expand Up @@ -214,15 +212,12 @@ async Task CreateJob(IScriptLogWriter writer, CancellationToken cancellationToke
Image = await containerResolver.GetContainerImageForCluster(),
Command = new List<string> { "bash" },
Args = new List<string>
{
$"/octopus/Work/{scriptTicket.TaskId}/bootstrapRunner.sh",
$"/octopus/Work/{scriptTicket.TaskId}",
$"/octopus/Work/{scriptTicket.TaskId}/{scriptName}"
}.Concat((workspace.ScriptArguments ?? Array.Empty<string>())
.SelectMany(arg => new[]
{
$"'{arg}'"
})).ToList(),
$"/octopus/Work/{scriptTicket.TaskId}/bootstrapRunner.sh",
$"/octopus/Work/{scriptTicket.TaskId}",
$"/octopus/Work/{scriptTicket.TaskId}/{scriptName}"
}.Concat(workspace.ScriptArguments ?? Array.Empty<string>())
.ToList(),
VolumeMounts = new List<V1VolumeMount>
{
new("/octopus", "tentacle-home"),
Expand Down Expand Up @@ -253,7 +248,6 @@ async Task CreateJob(IScriptLogWriter writer, CancellationToken cancellationToke
await jobService.CreateJob(job, cancellationToken);
}


void RecordScriptHasStarted(IScriptLogWriter writer)
{
try
Expand Down

0 comments on commit a3a2b22

Please sign in to comment.