Skip to main content

Create a task definition

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

Before you begin​

Steps​

1. Write the task definition file​

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

---
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 describes every field.

2. Publish the first version​

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​

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​