Skip to main content
Version: v4.4.0

Create a Task

Before you begin

Task allows you to create operations executed by commands that complement the STK CLI Core commands. Tasks are like customizable commands that act in the context of the project or the user's Stack.

info

Tasks must be made available in the Stacks, but it is not mandatory for a Stack to have Tasks.

You can create a Task to perform operations:

  • Configure a local environment;
  • Deploy;
  • Execute scripts.

A Task is an independent structure of others YAML files. For more details, see Configure .yaml Files page.

Prerequisites

  • You must have a Stack.

Follow one of these steps below to create a Task:

  1. Use an existing Stack;
  2. Create a Stack. For more details, see the Create a Stack tutorial.

Create a Task

The Task needs a base structure to receive operations. Follow the steps:

Step 1. Access a Stack

Go to the Stack's folder or where the Stack was created and execute without the braces < > the command below to enter the Stack folder:

cd <TEXT-WITH-STACK-NAME>

Step 2. Create a Task**

Inside your Stack folder, run without the braces < > the command below:

stk create task <TEXT-WITH-TASK-NAME>

Example:

stk create task task-example

Next, enter a description for your Task:

Example:

? Description: Creating Tasks example

That's it! You have created your task, the output on the terminal should be:

- Task-example task successfully created!

Step 3. Edit the Task.yaml file**

In your Stack folder, a new folder named tasks has been created. Inside it, you will find the folder named after your Task and in the task.yaml file, which is pre-filled with the following information:

  • Task Name;
  • Task description;
  • Inputs examples;
  • Parameters to enter the operating system;
  • Parameters to inform the operation's commands the task should perform.
name: task-example
description: Task creation example
inputs:
- label: commit message
type: text
default: example
name: message
required: 'true
supported-os:
- windows
- linux
- mac
requirements-check:
dependency-example:
check-command: git --version
info: git is not installed
command: git add . ; git commit -m "{{inputs.message}}"

The yaml on the Task's example is already filled with the operation that fills in the message and performs a commit on Git. You need to edit the fields and add new inputs according to the Stack or project you want to create.

For more details about the inputs and other Task's parameters, see the Task yaml page.

Step 4. Test the Task running

Use the stk run command with the parameter -p or --task-path to test it.

From the terminal, run without the braces < > the command below:

stk run -p or --task-path <SUBBLE-TASK-CREATE>

Example:

stk run -p /Users/stackspot/hello-stacker/task-example

This Task example runs correctly and displays the result in the terminal if Git is correctly installed and configured on your computer.
Your Stack must have the files changed so the Git commands sequence defined in the Task runs without any errors.

Read more

See Task commands:

Was this page helpful?