Skip to content

Allow custom, non-zero exit code for core.setFailed #459

@sudomateo

Description

@sudomateo

Currently, the core.setFailed function exits with an exit code of 1. However, certain applications use a non-zero exit code to indicate behavior to the user. One such example is the -detailed-exitcode argument to terraform plan (source). The ask here is to configure the core.setFailed function to accept a custom, non-zero exit code.

This will allow users of the core package to do something like this in their JavaScript actions.

const exitCode = 2
core.setFailed(`Failed with ${exitCode}`, exitCode);

I believe this change would work but I'll admit my TypeScript knowledge is novice at best.

export function setFailed(message: string | Error, code = ExitCode.Failure): void {
  process.exitCode = code

  error(message)
}

It might be required to add logic to ensure the passed in exit code is non-zero and non-negative since this is a setFailed function after all and we don't want someone calling core.setFailed("Failed", 0).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions