Skip to content
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
16 changes: 16 additions & 0 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"

"github.com/spf13/pflag"

Expand All @@ -28,19 +29,34 @@ func main() {
Color: flags.Color,
}
if err, ok := err.(*errors.TaskRunError); ok && flags.ExitCode {
emitCIErrorAnnotation(err)
l.Errf(logger.Red, "%v\n", err)
os.Exit(err.TaskExitCode())
}
if err, ok := err.(errors.TaskError); ok {
emitCIErrorAnnotation(err)
l.Errf(logger.Red, "%v\n", err)
os.Exit(err.Code())
}
emitCIErrorAnnotation(err)
l.Errf(logger.Red, "%v\n", err)
os.Exit(errors.CodeUnknown)
}
os.Exit(errors.CodeOk)
}

// emitCIErrorAnnotation emits an error annotation for supported CI providers.
func emitCIErrorAnnotation(err error) {
if isGA, _ := strconv.ParseBool(os.Getenv("GITHUB_ACTIONS")); !isGA {
return
}
if e, ok := err.(*errors.TaskRunError); ok {
fmt.Fprintf(os.Stdout, "::error title=Task '%s' failed::%v\n", e.TaskName, e.Err)
return
}
fmt.Fprintf(os.Stdout, "::error title=Task failed::%v\n", err)
}

func run() error {
log := &logger.Logger{
Stdout: os.Stdout,
Expand Down
22 changes: 22 additions & 0 deletions website/src/docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2290,6 +2290,28 @@ The `output` option can also be specified by the `--output` or `-o` flags.

:::

## CI Integration

### Colored output

Task automatically enables colored output when running in CI environments
(`CI=true`). Most CI providers set this variable automatically.

You can also force colored output with `FORCE_COLOR=1` or disable it with
`NO_COLOR=1`.

### Error annotations

When running in GitHub Actions (`GITHUB_ACTIONS=true`), Task automatically emits
error annotations when a task fails. These annotations appear in the workflow
summary, making it easier to spot failures without scrolling through logs.

```shell
::error title=Task 'build' failed::exit status 1
```

This feature requires no configuration and works automatically.

## Interactive CLI application

When running interactive CLI applications inside Task they can sometimes behave
Expand Down
Loading