Tasks Overview
Tasks are reusable automation workflows that encapsulate complex operations into simple, parameterized commands. They form the backbone of Xec's automation capabilities, enabling you to define once and execute anywhere.
What Are Tasks?
Tasks are named sequences of commands that can:
- Execute across multiple targets
- Accept parameters
- Handle errors gracefully
- Run steps conditionally
- Execute in parallel
- Emit and respond to events
- Be composed into larger workflows
Basic Task Structure
tasks:
# Simple command task
hello:
command: echo "Hello, World!"
# Multi-step task
deploy:
description: Deploy application
steps:
- command: git pull
- command: npm install
- command: npm run build
- command: pm2 restart app
Task Types
1. Command Tasks
Single command execution:
tasks:
backup:
command: tar -czf backup.tar.gz /data
target: backup-server
2. Script Tasks
Execute scripts:
tasks:
process:
script: |
const data = await fetchData();
const processed = transform(data);
await save(processed);
description: Process data pipeline
3. Multi-Step Tasks
Complex workflows:
tasks:
release:
steps:
- name: Run tests
command: npm test
- name: Build application
command: npm run build
- name: Deploy to production
task: deploy-prod