|
| 1 | +--- |
| 2 | +title: "CLI tasks commands" |
| 3 | +sidebarTitle: "tasks" |
| 4 | +description: "Use these commands to trigger tasks from your terminal." |
| 5 | +--- |
| 6 | + |
| 7 | +import CommonOptions from "/snippets/cli-options-common.mdx"; |
| 8 | +import ConfigFileOptions from "/snippets/cli-options-config-file.mdx"; |
| 9 | +import ProjectRefOptions from "/snippets/cli-options-project-ref.mdx"; |
| 10 | + |
| 11 | +## tasks trigger |
| 12 | + |
| 13 | +Triggers a task and prints the run ID and its dashboard URL. It runs in the `dev` environment unless you pass `--env`, so start the [dev command](/cli-dev-commands) first. |
| 14 | + |
| 15 | +<CodeGroup> |
| 16 | + |
| 17 | +```bash npm |
| 18 | +npx trigger.dev@latest tasks trigger hello-world --payload '{"name":"Ada"}' |
| 19 | +``` |
| 20 | + |
| 21 | +```bash pnpm |
| 22 | +pnpm dlx trigger.dev@latest tasks trigger hello-world --payload '{"name":"Ada"}' |
| 23 | +``` |
| 24 | + |
| 25 | +```bash yarn |
| 26 | +yarn dlx trigger.dev@latest tasks trigger hello-world --payload '{"name":"Ada"}' |
| 27 | +``` |
| 28 | + |
| 29 | +</CodeGroup> |
| 30 | + |
| 31 | +Add `--wait` to wait for the run to finish. It prints the run's output, or its error and exits with code 1 if the run failed, which makes it useful in scripts and for coding agents testing a task: |
| 32 | + |
| 33 | +```bash |
| 34 | +npx trigger.dev@latest tasks trigger hello-world --payload '{"name":"Ada"}' --wait |
| 35 | +``` |
| 36 | + |
| 37 | +The command fails without creating a run if the current version has no task with that ID. In `dev`, it warns you when the dev command isn't running, because the run waits in the queue until it starts. |
| 38 | + |
| 39 | +<ParamField body="Payload" type="--payload"> |
| 40 | + The payload as JSON, e.g. `--payload '{"name":"Ada"}'`. Without it, the task gets no payload. |
| 41 | +</ParamField> |
| 42 | + |
| 43 | +<ParamField body="Payload file" type="--payload-file"> |
| 44 | + Read the payload from a JSON file instead. |
| 45 | +</ParamField> |
| 46 | + |
| 47 | +<ParamField body="Wait" type="--wait"> |
| 48 | + Wait for the run to finish, then print its output or error. |
| 49 | +</ParamField> |
| 50 | + |
| 51 | +<ParamField body="Timeout" type="--timeout"> |
| 52 | + With `--wait`, stop waiting after this many seconds and exit with code 1. |
| 53 | +</ParamField> |
| 54 | + |
| 55 | +<ParamField body="Tag" type="--tag"> |
| 56 | + A tag to add to the run. Repeat it to add more than one, e.g. `--tag cli --tag test`. |
| 57 | +</ParamField> |
| 58 | + |
| 59 | +<ParamField body="Idempotency key" type="--idempotency-key"> |
| 60 | + If a run with this key already exists, return it instead of creating a new one. See [idempotency](/idempotency). |
| 61 | +</ParamField> |
| 62 | + |
| 63 | +<ParamField body="Delay" type="--delay"> |
| 64 | + Wait before running, e.g. `30s`, `5m` or an ISO 8601 date. |
| 65 | +</ParamField> |
| 66 | + |
| 67 | +<ParamField body="TTL" type="--ttl"> |
| 68 | + Expire the run if it hasn't started within this time, e.g. `10m`. |
| 69 | +</ParamField> |
| 70 | + |
| 71 | +<ParamField body="Queue" type="--queue"> |
| 72 | + The queue to run in, instead of the queue set on the task. |
| 73 | +</ParamField> |
| 74 | + |
| 75 | +<ParamField body="Machine" type="--machine"> |
| 76 | + The machine to run on, e.g. `small-2x`. See [machines](/machines). Has no effect in `dev`. |
| 77 | +</ParamField> |
| 78 | + |
| 79 | +## Options |
| 80 | + |
| 81 | +<ParamField body="Environment" type="--env | -e"> |
| 82 | + The environment to use: `dev`, `prod`, `staging` or `preview`. Defaults to `dev`. |
| 83 | +</ParamField> |
| 84 | + |
| 85 | +<ConfigFileOptions /> |
| 86 | +<ProjectRefOptions /> |
| 87 | +<ParamField body="Branch" type="--branch | -b"> |
| 88 | + The branch to use. Required with `--env preview`. In `dev`, it defaults to the same [dev branch](/deployment/dev-branches) as the dev command. |
| 89 | +</ParamField> |
| 90 | + |
| 91 | +### Common options |
| 92 | + |
| 93 | +These options are available on most commands. |
| 94 | + |
| 95 | +<CommonOptions /> |
0 commit comments