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-taskin 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
- You have completed Set up your account and Log in with the CLI: 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:
---
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:
nameanddescriptionare the title and the one-line summary the platform shows, andcategoryis the kind of task Swale Hub files it under once it is public.inputsare the values a workflow passes in.messagehas a default, so a workflow can leave it out.outputsare the values the task returns. The task writesechoed_messageto the file named byWORKFLOW_TASK_OUTPUT.execis the container: the publicbusyboximage 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
- Run your first workflow, which runs this task
- Publishing versions, making a task definition public, and deleting: Create and manage task definitions
- Task definition syntax