Commands and Script tasks
Types of tasks for executing programming languages.
For each of the supported languages (e.g. Python, R, Node.js, Shell), Kestra provides two types of tasks: Script and Commands.
- The
Script
tasks — typically written inline in the YAML flow configuration. They are best suited for short scripts and they make it easy to pass data from flow inputs and other tasks to your custom scripts. - The
Commands
tasks — best suited for more complex and longer scripts, typically integrated into kestra as namespace files.
The following table gives an overview of all script tasks and their configuration.
Language | Default image | beforeCommands example | Script example | Commands example |
---|---|---|---|---|
Python | python | pip install requests kestra | print("Hello World!") | python hello.py |
R | r-base | Rscript -e "install.packages('dplyr')" | print("Hello World!") | Rscript hello.R |
Julia | julia | julia -e 'using Pkg; Pkg.add("CSV")' | println("Hello World!") | julia hello.jl |
Ruby | ruby | gem install httparty | puts "Hello World!" | ruby hello.rb |
Node.js | node | npm install json2csv | console.log('Hello World!'); | node hello.js |
Shell | ubuntu | apt-get install curl | echo "Hello World!" | ./hello.bash |
Powershell | powershell | Install-Module -Name ImportExcel | Write-Output "Hello World!" | .\hello.ps1 |
Full class names:
- io.kestra.plugin.scripts.python.Commands
- io.kestra.plugin.scripts.python.Script
- io.kestra.plugin.scripts.r.Commands
- io.kestra.plugin.scripts.r.Script
- io.kestra.plugin.scripts.julia.Commands
- io.kestra.plugin.scripts.julia.Script
- io.kestra.plugin.scripts.ruby.Commands
- io.kestra.plugin.scripts.ruby.Script
- io.kestra.plugin.scripts.node.Commands
- io.kestra.plugin.scripts.node.Script
- io.kestra.plugin.scripts.shell.Commands
- io.kestra.plugin.scripts.shell.Script
- io.kestra.plugin.scripts.powershell.Commands
- io.kestra.plugin.scripts.powershell.Script
Check available blueprints to get started with those tasks.
When to use Script
over Commands
?
The Script
pattern has several advantages:
- Simplicity: the script code is stored and versioned using Kestra's revision history along with your orchestration logic.
- Easier integration with the templating engine: when the entire workflow is defined in one configuration file, it can be easier to access flow inputs, variable definitions, pass outputs to downstream tasks, etc.
However, the Script
tasks also have some disadvantages as compared to the Commands
tasks:
- Readability: adding scripts into a YAML configuration file makes the scripts less readable, especially if they get long. Inline scripts also lack the syntax highlighting and testability that you would get when leveraging our embedded Code Editor instead.
- Complex use cases: if your business logic comprises multiple files importing classes and functions from other modules, you will need to use the
Commands
tasks instead.
Overall, we recommend using Commands
tasks for advanced production workloads. However, the Script
tasks offer a great alternative for simple use cases.
Was this page helpful?