Description
The stk-legacy create task
command creates a base file of a Task in the current Stack.
How does it work?
You create a folder with the Task's name and in it, a task.yaml
file is also created. You have to edit it to define the tasks that will be performed by your Task.
Parameters
Check the available options in the command:
Parameter | Description |
---|---|
NAME | Sets the Task's name in your Stack. |
--description | Defines your Task's description. |
Example
See an example below of how to create a Task:
- Create a Stack locally, run the command:
stk-legacy create stack <your-stack-name>
- Enter the Stack directory that you created:
cd <your-stack-name>
- Inside the Stack directory, create your Task:
stk-legacy create task <your-task-name>
- Describe what your Task does:
? Description: <text-description-task>
- Your Task has been created:
- Task <your-task-name> successfully created!
- The
task.yaml
file was created in the folder named after your Task, and in thetasks
folder in the current Stack:
name: <your-task-name>
description: <text-description-task>
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}}"
Attributes:
- name: Your Task's name that will be used via the
stk-legacy run
command. - description: The Task's description will be shown in the
stk-legacy list task
command. - inputs: Objects with the values of the inputs that will be passed to the commands to be executed by the Task. They are not required. If any input value defined in the Task is not entered, the user will be prompted for it.
- supported-os: Definition of which operating systems the Task will be compatible with. The options are:
windows
mac
linux
- requirements-check:
[Optional]
List of requirements that will be checked before the command list is executed.- check-command: Command executed during the requirements check.
- info: Message that will be displayed if the check for this requirement fails.
- container:
[Optional]
Run task inside a Docker container.- image: Url of the image or path relative to the Dockerfile inside the Task directory.
- volumes: List of volumes to be mounted during the container execution (e.g. "/storage:/data").
- command: Command or list of commands that will be executed by the Task. You can split execution by operating system using the objects with the name of the operating system. As in the following example:
command:
windows: |
echo "I'm on windows"
git add . & git commit -m "{{inputs.message}}"
mac: |
echo "I'm on mac"
git add . ; git commit -m "{{inputs.message}}"
linux: |
echo "I'm on linux"
git add . ; git commit -m "{{inputs.message}}"
task.yaml files example
See some Tasks' examples below:
- Task that runs other scripts in the same folder as task.yaml.
name: run-script-task
description: Task that runs scripts contained in the task folder.
inputs:
- label: Script Name
type: text
name: name
required: true
supported-os:
- windows
- linux
- mac
command:
windows: |
call {{component_path}}/{{inputs.name}}.bat
linux: |
chmod +x {{component_path}}/{{inputs.name}}.sh
{{component_path}}/{{inputs.name}}.sh
mac: |
chmod +x {{component_path}}/{{inputs.name}}.sh
{{component_path}}/{{inputs.name}}.sh
There are some variables set during Task execution that you can use to get the Task path.
- component_path: Path to the folder where the Task is running.
- stack_path: Path to the Stack folder where the Task being executed is contained.
- Task that runs Python code:
name: run-python-code
description: Task that executes Python code.
inputs:
- label: Number of loops
type: int
name: loops
default: 5
supported-os:
- linux
- mac
requirements-check:
is-python-installed:
check-command: python --version
info: Python is not installed.
command:
linux: |
#!/usr/bin/env python
for i in range({{inputs.loops}}):
print("Hello from Python")
mac: |
#!/usr/bin/env python
for i in range({{inputs.loops}}):
print("Hello from Python")
- The use of
shebangs
for programmatic code execution is only supported on theLinux
andMacOs
operating systems.
- Task running inside an alpine container
name: run-alpine
description: Task using an alpine
inputs:
- label: URL
type: text
name: url
default: https://stackspot.com
container:
image: alpine
supported-os:
- linux
- mac
requirements-check:
is-docker-installed:
check-command: docker --version
info: Docker is not installed.
command: |
apk add curl jq
curl -s "{{ url }}" | jq
If necessary it is possible to invalidate the docker cache by using the
--no-docker-cache
parameter during task execution.
Command execution example
Read more
Was this page helpful?