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

Add new input "end-pipeline-step-before-task-finish" to terminate the pipeline step if the Fargate task has not finished executing. #20

Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Will pass the following command to the container on the AWS ECS Fargate task:
| override-container-environment | Add or override existing environment variables if `override-container` is passed. Provide one per line in key=value format. | `false` | |
| tail-logs | If set to true, will try to extract the logConfiguration for the first container in the task definition. If `override-container` is passed, it will extract the logConfiguration from that container. Tailing logs is only possible if the provided container uses the `awslogs` logDriver. | `false` | true |
| task-stopped-wait-for-max-attempts | How many times to check if the task is stopped before failing the action. The delay between each check is 6 seconds. | `false` | 100 |
| end-pipeline-step-before-task-finish | Terminate the pipeline step if the Fargate task has not finished executing. | `false` | `false` |
<!-- action-docs-inputs -->

<!-- action-docs-outputs -->
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ inputs:
required: false
default: 100

end-pipeline-step-before-task-finish:
description: >-
Terminate the pipeline step if the Fargate task has not finished executing.
required: false
default: 'false'

outputs:
task-arn:
description: 'The full ARN for the task that was ran.'
Expand Down
50 changes: 29 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const main = async () => {
const overrideContainerCommand = core.getMultilineInput('override-container-command', {required: false});
const overrideContainerEnvironment = core.getMultilineInput('override-container-environment', {required: false});
const taskStoppedWaitForMaxAttempts = parseInt(core.getInput('task-stopped-wait-for-max-attempts', {required: false}));
const endPipelineStepBeforeTaskEnd = core.getBooleanInput('end-pipeline-step-before-task-finish', {required: false});

// Build Task parameters
const taskRequestParams = {
Expand Down Expand Up @@ -154,32 +155,39 @@ const main = async () => {
}
}

// Wait for Task to finish
core.debug(`Waiting for task to finish.`);
await ecs.waitFor('tasksStopped', {
cluster,
tasks: [taskArn],
$waiter: {delay: 6, maxAttempts: taskStoppedWaitForMaxAttempts}}
).promise();
if (endPipelineStepBeforeTaskEnd === false){

// Close LogStream and store output
if (logFilterStream !== null) {
core.debug(`Closing logStream.`);
logFilterStream.close();
// Wait for Task to finish
core.debug(`Waiting for task to finish.`);
await ecs.waitFor('tasksStopped', {
cluster,
tasks: [taskArn],
$waiter: {delay: 6, maxAttempts: taskStoppedWaitForMaxAttempts}}
).promise();

// Export log-output
core.setOutput('log-output', logOutput);
}
// Close LogStream and store output
if (logFilterStream !== null) {
core.debug(`Closing logStream.`);
logFilterStream.close();

// Export log-output
core.setOutput('log-output', logOutput);
}

// Describe Task to get Exit Code and Exceptions
core.debug(`Process exit code and exception.`);
task = await ecs.describeTasks({cluster, tasks: [taskArn]}).promise();
// Describe Task to get Exit Code and Exceptions
core.debug(`Process exit code and exception.`);
task = await ecs.describeTasks({cluster, tasks: [taskArn]}).promise();

// Get exitCode
if (task.tasks[0].containers[0].exitCode !== 0) {
core.info(`Task failed, see details on Amazon ECS console: https://console.aws.amazon.com/ecs/home?region=${aws.config.region}#/clusters/${cluster}/tasks/${taskId}/details`);
core.setFailed(task.tasks[0].stoppedReason)
// Get exitCode
if (task.tasks[0].containers[0].exitCode !== 0) {
core.info(`Task failed, see details on Amazon ECS console: https://console.aws.amazon.com/ecs/home?region=${aws.config.region}#/clusters/${cluster}/tasks/${taskId}/details`);
core.setFailed(task.tasks[0].stoppedReason)
}
}
else{
core.info("ECS Task running...")
}

} catch (error) {
core.setFailed(error.message);
core.debug(error.stack);
Expand Down