Script
type: "io.kestra.plugin.scripts.ruby.Script"
Execute a Ruby script.
Examples
Create a Ruby script and execute it. The easiest way to create a Ruby script is to use the embedded VS Code editor. Create a file named
main.rb
and paste the following code:
require 'csv'
require 'json'
file = File.read('data.json')
data_hash = JSON.parse(file)
# Extract headers
headers = data_hash.first.keys
# Convert hashes to arrays
data = data_hash.map(&:values)
# Prepend headers to data
data.unshift(headers)
# Create and write data to CSV file
CSV.open('output.csv', 'wb') do |csv|
data.each { |row| csv << row }
end
In order to read that script from the Namespace File called main.rb
, you can leverage the {{ read('main.rb') }}
function.
Also, note how we use the inputFiles
option to read additional files into the script's working directory. In this case, we read the data.json
file, which contains the data that we want to convert to CSV.
Finally, we use the outputFiles
option to specify that we want to output the output.csv
file that is generated by the script. This allows us to access the file in the UI's Output tab and download it, or pass it to other tasks.
id: generate_csv
namespace: company.team
tasks:
- id: bash
type: io.kestra.plugin.scripts.ruby.Script
inputFiles:
data.json: |
[
{"Name": "Alice", "Age": 30, "City": "New York"},
{"Name": "Bob", "Age": 22, "City": "Los Angeles"},
{"Name": "Charlie", "Age": 35, "City": "Chicago"}
]
beforeCommands:
- ruby -v
script: "{{ read('main.rb') }}"
outputFiles:
- "*.csv"
Properties
interpreter
- Type: array
- SubType: string
- Dynamic: ❌
- Required: ✔️
- Default:
[/bin/sh, -c]
- Min items:
1
Which interpreter to use.
script
- Type: string
- Dynamic: ✔️
- Required: ✔️
- Min length:
1
The inline script content. This property is intended for the script file's content as a (multiline) string, not a path to a file. To run a command from a file such as bash myscript.sh
or python myscript.py
, use the Commands
task instead.
warningOnStdErr
- Type: boolean
- Dynamic: ❌
- Required: ✔️
- Default:
true
Whether to set the task state to WARNING
if any stdErr
is emitted.
beforeCommands
- Type: array
- SubType: string
- Dynamic: ✔️
- Required: ❌
A list of commands that will run before the commands
, allowing to set up the environment e.g. pip install -r requirements.txt
.
containerImage
- Type: string
- Dynamic: ✔️
- Required: ❌
- Default:
ruby
The task runner container image, only used if the task runner is container-based.
docker
⚠ Deprecated
- Type: DockerOptions
- Dynamic: ❓
- Required: ❌
Deprecated - use the 'taskRunner' property instead.
Only used if the
taskRunner
property is not set
env
- Type: object
- SubType: string
- Dynamic: ✔️
- Required: ❌
Additional environment variables for the current process.
failFast
- Type: boolean
- Dynamic: ❌
- Required: ❌
- Default:
true
Fail the task on the first command with a non-zero status.
If set to
false
all commands will be executed one after the other. The final state of task execution is determined by the last command. Note that this property maybe be ignored if a non compatible interpreter is specified. You can also disable it if your interpreter does not support theset -e
option.