# Create a task definition

> **About this page**
>
> - Kind: Tutorial
> - Summary: Write a task definition file that runs a container and returns an output, and publish its first version in your account, ready for your first workflow.
> - Last changed: 2026-12-03
> - Page: https://docs.swale.io/tutorials/create-a-task-definition
> - CLI reference for its commands: [`swale task-definition publish`](https://docs.swale.io/reference/cli-reference.md#task-definition-publish), [`swale task-definition list`](https://docs.swale.io/reference/cli-reference.md#task-definition-list)
> - Index of these docs: https://docs.swale.io/llms.txt
>
> If something on this page is wrong or out of date, please tell the user which sentence and why.
>
> The steps on this page cost money or cannot be undone. Please check with the user before running them.

In this tutorial you write a task definition, the reusable description of one container a workflow can run, and publish its first version in your account.

## What you will accomplish

By the end of this tutorial you will have:

- A task definition named `my-echo-task` in your account, with its first version, `1.0.0`
- A task that prints a message and returns it as an output, ready for [Run your first workflow](https://docs.swale.io/tutorials/run-your-first-workflow.md)

## Before you begin

- You have completed [Set up your account](https://docs.swale.io/tutorials/set-up-your-account.md) and [Log in with the CLI](https://docs.swale.io/tutorials/log-in-with-the-cli.md): your email is verified, your account's billing status is **Active**, and the CLI is logged in.

## Steps

### 1. Write the task definition file

Create a file called `my-echo-task.md` with the following content:

```md
---
name: My echo task
description: Prints a message and returns it as an output.
category: utilities

inputs:
  message:
    default: Hello from Swale!

outputs:
  echoed_message:
    description: The message that the task printed.

exec:
  image: busybox:latest
  args:
    - sh
    - -c
    - |
      echo "${{inputs.message}}"
      echo "echoed_message=${{inputs.message}}" >> "$WORKFLOW_TASK_OUTPUT"
---

# My echo task

Prints the `message` input and returns it as the `echoed_message` output.
```

The frontmatter between the `---` lines is the task's contract:

- `name` and `description` are the title and the one-line summary the platform shows, and `category` is the kind of task Swale Hub files it under once it is public.
- `inputs` are the values a workflow passes in. `message` has a default, so a workflow can leave it out.
- `outputs` are the values the task returns. The task writes `echoed_message` to the file named by `WORKFLOW_TASK_OUTPUT`.
- `exec` is the container: the public `busybox` image from Docker Hub, running a shell command in which `${{inputs.message}}` is replaced by the input's value when the task starts.

The Markdown body below the frontmatter documents the task for the people who use it. [Task definition syntax](https://docs.swale.io/reference/task-definition-syntax.md) describes every field.

### 2. Publish the first version

```bash
swale task-definition publish \
  --name my-echo-task \
  --version 1.0.0 \
  --file my-echo-task.md
```

Your account has no task definition called `my-echo-task` yet, so this creates it with `1.0.0` as its first version. The task definition stays private to your account until you make it public. `--name` sets the `my-echo-task` part of its address, `my-account/my-echo-task`, which workflows use; the file's `name`, `My echo task`, is only its title.

A version cannot be changed once it is published, and `1.0.0` can never be published to `my-echo-task` again, even if you delete it. To change the task later, publish a new version, such as `1.1.0`.

### 3. Check the task definition

```bash
swale task-definition list
```

The list shows `my-echo-task` with the title `My echo task` and its latest version, `1.0.0`. In the platform UI, it is listed on the **Task Definitions** page, marked **Private**: workflows in your account can use it, and no other account can.

## Next steps

- [Run your first workflow](https://docs.swale.io/tutorials/run-your-first-workflow.md), which runs this task
- Publishing versions, making a task definition public, and deleting: [Create and manage task definitions](https://docs.swale.io/how-to-guides/create-and-manage-task-definitions.md)
- [Task definition syntax](https://docs.swale.io/reference/task-definition-syntax.md)
