After

When you specify dependencies using the use keyword, the task inherits the file system contents and environment variables of its dependencies.

If you want to run tasks after other tasks without inheriting the output of the dependencies, you should use the after keyword instead.

Common reasons to use after include:

  • Continuous Deployment workflows, where tasks modify external resources and need to run in a specific order
  • ETL workflows, where state is stored externally and tasks need to run in a specific order
  • Optimizing build minutes by making sure some tasks succeed before running others

Example

tasks:
  - key: one
    run: echo this is task one

  - key: two
    run: echo this is task two

  - key: three
    after: [one, two]
    run: echo "task three waits for one and two to succeed before running"

When after is a list, the task runs only if every task in the list succeeds.

Running tasks after other tasks fail

To run a task based on how other tasks ended, set after to an expression instead of a list. The expression checks the status attributes of other tasks, and can combine them with && and ||.

tasks:
  - key: one
    run: exit 1

  - key: if-one-fails
    after: ${{ one.failed }}
    run: echo task one failed!

These expressions cover the common cases:

  • ${{ example-task.finished }} runs after example-task fully executes, regardless of if it succeeded or failed. If example-task doesn't finish (for example, if it is cancelled), then this task will be skipped.
  • ${{ example-task.failed && example-task.finished }} runs only if the task executed and then failed, for example by exiting with a non-zero status.

A task is skipped if any task in its use doesn't succeed, even when its after expression is true. If you might need data from a task even when it fails, such as a coverage report, make sure to save that output as an artifact.

Status attributes

Each task in an after expression has the following attributes. ✅ marks the attributes that are true for each way a task can end.

outcomesucceededfailedfinishedcache-hitabortedcancelledtimed-outskipped
Executed and succeeded✅✅
Executed and failed✅✅
Cache hit✅✅✅
Cancelled✅✅✅
Timed out✅✅✅
Aborted for another reason✅✅
Skipped✅