Deprecated handlebars
Handlebars are deprecated and superseded by Pebble. These functions will be removed soon and are disabled by default.
boolean
eq
: Equality
Test if two elements are equals.
Render
yes
orno
:
{{ #eq a b }}
yes
{{ else }}
no
{{ /eq }}
Render
true
orfalse
:
{{ eq a b }}
Render
yes
orno
:
{{ eq a b yes='yes' no='no' }}
neq
: Not equality
Test if two elements are NOT equals.
Render
yes
orno
:
{{ #neq a b }}
yes
{{ else }}
no
{{ /neq }}
Render
true
orfalse
:
{{ neq a b }}
Render
yes
orno
:
{{ neq a b yes='yes' no='no' }}
gt
: Greater operator
Greater operator (arguments must be Comparable elements).
Render
yes
orno
:
{{ #gt a b }}
yes
{{ else }}
no
{{ /gt }}
Render
true
orfalse
:
{{ gt a b }}
Render
yes
orno
:
{{ gte a b yes='yes' no='no' }}
gte
: Greater or equal operator
Greater or equal operator (arguments must be Comparable elements).
Render
yes
orno
:
{{ #gte a b }}
yes
{{ else }}
no
{{ /gte }}
Render
true
orfalse
:
{{ gte a b }}
Render
yes
orno
:
{{ gte a b yes='yes' no='no' }}
lt
: Less operator
Less than operator (arguments must be Comparable elements).
Render
yes
orno
:
{{ #lt a b }}
yes
{{ else }}
no
{{ /lt }}
Render
true
orfalse
:
{{ lt a b }}
Render
yes
orno
:
{{ lt a b yes='yes' no='no' }}
lte
: Less or equal operator
Less than operator (arguments must be Comparable elements.
Render
yes
orno
:
{{ #lte a b }}
yes
{{ else }}
no
{{ /lte }}
Render
true
orfalse
:
{{ lte a b }}
Render
yes
orno
:
{{ lte a b yes='yes' no='no' }}
and
: And operator
And operator. This is a boolean operation.
Truthiness of arguments is determined by isEmpty, so this helper can be used with non-boolean values.
Multiple arguments are supported too:
{{ #and a b c d }}
yes
{{ else }}
no
{{ /and }}
Render
yes
orno
:
{{ #and a b }}
yes
{{ else}}
no
{{ /and }}
Render
true
orfalse
:
{{ and a b }}
Render
yes
orno
:
{{ and a b yes='yes' no='no' }}
or
: Or operator
Or operator. This is a boolean operation
Truthiness of arguments is determined by isEmpty, so this helper can be used with non-boolean values.
Multiple arguments are supported too:
{{ #or a b c d }}
yes
{{ else }}
no
{{ /or }}
Render
yes
orno
:
{{ #or a b }}
yes
{{ else }}
no
{{ /or }}
Render
true
orfalse
:
{{ or a b }}
Render
yes
orno
:
{{ or a b yes='yes' no='no' }}
not
: Not operator
Truthiness of arguments is determined by isEmpty, so this helper can be used with non-boolean values.
Render
yes
orno
:
{{ #not a }}
yes
{{ else }}
no
{{ /not }}
Render
true
orfalse
:
{{ not a }}
Render
y
orn
:
{{ not a yes='yes' no='no' }}
cmp
: Compare operator
Compare to object as Comparables.
Renders 1 if a > b, 0 if a == b -1 if a < b
{{ cmp a b }}
isNull
: Compare operator
Test if one element is null.
{{ isNull a }}
isNotNull
: Compare operator
Test if one element is not null.
{{ isNotNull a }}
date
dateFormat
: Date format
{{ dateFormat date ['format'] [format='format'][tz=timeZone | timeZoneId] }}
## Arguments:
format
: Format parameters is one of:full
: Sunday, September 8, 2013 at 4:19:12 PM Central European Summer Timelong
: September 8, 2013 at 4:19:12 PM CESTmedium
: Sep 8, 2013, 4:19:12 PMshort
: 9/8/13, 4:19 PMiso
: 2013-09-08T16:19:12.000000+02:00iso_sec
: 2013-09-08T16:19:12+02:00sql
: 2013-09-08 16:19:12.000000sql_seq
: 2013-09-08 16:19:12iso_date_time
: 2013-09-08T16:19:12+02:00Europe/Parisiso_date
: 2013-09-08+02:00iso_time
: 16:19:12+02:00iso_local_date
: 2013-09-08iso_instant
: 2013-09-08T14:19:12Ziso_local_date_time
: 2013-09-08T16:19:12iso_local_time
: 16:19:12iso_offset_time
: 16:19:12+02:00iso_ordinal_date
: 2013-251+02:00iso_week_date
: 2013-W36-7+02:00iso_zoned_date_time
: 2013-09-08T16:19:12+02:00Europe/Parisrfc_1123_date_time
: Sun, 8 Sep 2013 16:19:12 +0200pattern
: a date pattern.- Otherwise, the default formatter
iso
will be used. The format option can be specified as a parameter or hash (a.k.a named parameter). - You can pass the any format from SimpleDateFormat
timezeome
: with the formatEurope/Paris
now
: Current date
{{ now ['format'] [tz=timeZone|timeZoneId] }}
## Arguments:
format
: Same format asdateFormat
timezone
: with the formatEurope/Paris
timestamp
: Current second timestamp
{{ timestamp }}
nanotimestamp
: Current nano timestamp
{{ nanotimestamp }}
microtimestamp
: Current micro timestamp
{{ microtimestamp }}
dateAdd
: Add some units to date
{{ dateAdd yourDate quantity "unit" [format="format"] [tz=timeZone|timeZoneId] }}
{{ dateAdd yourDate -1 "DAYS" }}
quantity
: an integer value positive or negativeformat
: Format parameters is one of:NANOS
MICROS
MILLIS
SECONDS
MINUTES
HOURS
HALF_DAYS
DAYS
WEEKS
MONTHS
YEARS
DECADES
CENTURIES
MILLENNIA
ERAS
index
Handlebars variables are deprecated and superseded by Pebble. These functions will be removed soon and are disabled by default.
Variables are specific fields for tasks. They use the power of handlebars with Kestra's special context system, allowing powerful task composition.
Variables can use variable information registered/existing in the execution context. The context is data injected in Variables and from different sources:
Functions
Sometimes, you need to change the format of variables. To do this, you can use some of the following functions:
---iterations
For each
You can iterate over a list using the built-in each helper. Inside the block, you can use this
to reference the element being iterated over. contextualListVariable
is an iterable item on which the mydata property is displayed for all entries.
The @index
is a special variable available in the each loop context which value is the current index of the element being iterated. There are agic* variables like @index in a each context. The following ones are also available: @key
@index
@first
@last
@odd
@even
See handlebars documentation for more about this topic.
{{ #each contextualListVariable }}
{{ this.mydata }} {{ @index }}
{{ /each }}
will produce
one 0
two 1
three 2
django! 3
for the following data sample when
contextualListVariable = [
{"mydata": "one"},
{"mydata": "two"},
{"mydata": "three"},
{"mydata": "django!"},
]
If the contextual 'this' is not convenient to use the data as you wish, it is possible to alias it as shown below:
{{ #each iterableVariable as | myItem | }}
{{myItem.mydata}}
{{ /each }}
json
json
Convert an object to json
Convert an object to is JSON representation
{{ json output['task-id'] }}
Example, if the current context is:
{
"outputs": {
"task1": {
"value": 1,
"text": "awesome1"
},
"task2": {
"value": 2,
"text": "awesome2"
}
}
}
the output of {{ json outputs.task2}}
will be {"value":2,"text":"awesome2"}
.
jq
Transform vars with JQ
Apply the JQ expression to a variables.
{{ jq vars jqExpr [first=false] }}
first
mean to always fetch the first element, by default jq return an array of results
Internally, Jackson JQ is used and support only a large subset of official JQ.
Example, if the current context is:
{
"outputs": {
"task1": {
"value": 1,
"text": "awesome1"
},
"task2": {
"value": 2,
"text": "awesome2"
}
}
}
{{ jq outputs .task1.value true }}
the output will be 1
.
number
numberFormat
: Format a number
{{ numberFormat number ["format"] [locale=default] }}
Arguments:
format
: Format parameters is one of:- "integer": the integer number format
- "percent": the percent number format
- "currency": the decimal number format
- "pattern": a decimal pattern.
- Otherwise, the default formatter will be used.
More options:
- groupingUsed: Set whether or not grouping will be used in this format.
- maximumFractionDigits: Sets the maximum number of digits allowed in the fraction portion of a number.
- maximumIntegerDigits: Sets the maximum number of digits allowed in the integer portion of a number
- minimumFractionDigits: Sets the minimum number of digits allowed in the fraction portion of a number
- minimumIntegerDigits: Sets the minimum number of digits allowed in the integer portion of a number.
- parseIntegerOnly: Sets whether or not numbers should be parsed as integers only.
- roundingMode: Sets the {@link java.math.RoundingMode} used in this NumberFormat.
string
capitalizeFirst
: Capitalizes the first character of the value.
If the value is "kestra is cool !", the output will be "Kestra is cool !".
{{ capitalizeFirst value }}
center
: Centers the value in a field of a given width.
If the value is "Handlebars.java", the output will be " Handlebars.java ".
{{ center value size=19 [pad="char"] }}
## Arguments:
size
pad
cut
: Removes all values of arg from the given string.
If the value is "String with spaces", the output will be "Stringwithspaces".
{{ cut value [" "] }}
defaultIfEmpty
: Default if empty
If the value evaluates to False, it will use the given default. Otherwise, it uses the value. If value is "" (an empty string), the output will be nothing.
{{ defaultIfEmpty value ["nothing"] }}
join
: Join string
Joins an array, iterator or an iterable with a string.
{{ join value join [prefix=""] [suffix=""] }}
## Arguments:
join
prefix
suffix
If value is the list 'a', 'b', 'c', the output will be the string "a // b // c".
{{ join value " // " [prefix=""] [suffix=""] }}
Join the "a", "b", "c", the output will be the string "a // b // c".
{{ join "a" "b" "c" " // " [prefix=""] [suffix=""] }}
ljust
: Left-aligns the value in a field of a given width.
If the value is Handlebars.java, the output will be "Handlebars.java ".
{{ ljust value 20 [pad=" "] }}
## Arguments:
field size
rjust
: Right-aligns the value in a field of a given width.
If the value is Handlebars.java, the output will be " Handlebars.java".
{{ rjust value 20 [pad=" "] }}
## Arguments:
field size
pad
substring
Substring
Returns a new CharSequence
that is a subsequence of this sequence.
The subsequence starts with the char
value at the specified index and
ends with the char
value at nd - 1*
{{substring value start end }}
## Arguments:
start offset
end offset
For example:
If the value is Handlebars.java, the output will be "java".
{{ substring value 11 }}
If the value is Handlebars.java, the output will be "Handlebars".
{{ substring value 0 10 }}
lower
: Converts a string into all lowercase.
If the value is 'Still MAD At Yoko', the output will be 'still mad at yoko'.
{{ lower value}}
upper
Converts a string into all uppercase.
If the value is 'Hello', the output will be 'HELLO'.
{{ upper value }}
slugify
Converts to lowercase
This removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. It also strips leading and trailing whitespace. If the value is "Joel is a slug", the output will be "joel-is-a-slug".
{{ slugify value }}
stringFormat
: Formats the variable
According to the argument, a string formatting specifier. If the value is "Hello %s" "handlebars.java", the output will be "Hello handlebars.java".
{{stringFormat string param0 param1 ... paramN}}
## Arguments:
format
paramN
stripTags
: Strips all XHTML tags.
{{ stripTags value }}
capitalize
: Capitalizes all the whitespace separated words in a String.
If the value is "my first post", the output will be "My First Post".
{{ capitalize value [fully=false] }}
Arguments:
fully
abbreviate
: Truncates a string
The string will be truncated if it is longer than the specified number of characters. Truncated strings will end with a translatable ellipsis sequence ("..."). If value is "Handlebars rocks", the output will be "Handlebars...".
{{ abbreviate value 13 }}
## Arguments:
- Number of characters to truncate to
wordWrap
: Wraps words
This wraps the sentence at a specified line length. If value is Joel is a slug, the output would be: Joel\nis a\nslug
{{ wordWrap value 5 }}
## Arguments:
- the number of characters at which to wrap the text
replace
Replaces
Each substring of this string that matches the literal target sequence with the specified literal replacement sequence. If value is "Handlebars ...", the output will be "Handlebars rocks".
{{ replace value "..." "rocks" }}
yesno
: Boolean to yes / no
For true, false and (optionally) null, to the strings "yes", "no", "maybe".
## Arguments:
yes
no
maybe
{{ yesno value [yes="yes"] [no="no"] maybe=["maybe"] }}
use
Here you will find some examples to illustrate the available variables, and how to get the value you need.
Here is a typical payload for variables:
globals:
my-global-string: string
my-global-int: 1
my-global-bool: true
task:
id: float
type: io.kestra.plugin.core.debug.Return
taskrun:
id: 5vPQJxRGCgJJ4mubuIJOUf
startDate: 2020-12-18T12:46:36.018869Z
attemptsCount: 0
value: value2
parent:
taskrun:
value: valueA
outputs:
int: 1
parents:
- taskrun:
value: valueA
outputs:
int: 1
- taskrun:
value: valueB
outputs:
int: 2
flow:
id: inputs
namespace: company.team
execution:
id: 42mXSJ1MRCdEhpbGNPqeES
startDate: 2020-12-18T12:45:28.489187Z
outputs:
my-task-id-1: # standard task outputs
value: output-string
my-task-id-2: # standard task outputs
value: 42
my-each-task-id: # dynamic task (each)
value1: # outputs for value1
value: here is value1
value2: # outputs for value2
value: here is value2
inputs:
file: kestra:///org/kestra/tests/inputs/executions/42mXSJ1MRCdEhpbGNPqeES/inputs/file/application.yml
string: myString
instant: 2019-10-06T18:27:49Z
Common variables
As you can see, there are a lot of common variables that can be used in your flow, some of the most common examples are: {{ execution.id }}
, {{ execution.startDate }}
that allows you to change a file name or SQL query, for example.
Input variables
Input variables are simple to access with {{ execution.NAME }}
, where NAME
is the name of the declared in your flow. The data will be dependent on the type
of the inputs.
One special case for input variables is the FILE
type, where the file is prepended by kestra://
. This means the file is inside the internal Kestra storage. Most tasks will take this kind of URI as a property and will provide the same property output. This type of input variable allows the full file generated by one task to be used in another task.
Outputs variables One of Kestra's most important abilities is to use all outputs from previous tasks in the next one.
Without dynamic tasks (Each)
This is the simplest and most common way to use outputs in the next task. In order to fetch a variable, just use {{ outputs.ID.NAME }}
where:
ID
is the task idNAME
is the name of the output. Each task type can have any outputs that are documented on the part outputs of their docs. For example, Bash task can have{{ outputs.ID.exitCode }}
,{{ outputs.ID.outputFiles }}
,{{ outputs.ID.stdErrLineCount }}
, etc...
With dynamic tasks (Each)
This option is more complicated since Kestra will change the way the outputs are generated, since there can be multiple tasks with the same id, you will need to use {{ outputs.ID.VALUE.NAME }}
.
Most of the time, using Dynamic Tasks, you will need to fetch the current value of the iteration. This is done easily with {{ taskrun.value }}
.
But what if a more complex flow is built, for example, with each containing 1 task (t1
) to download a file (based on each value), and a second one (t2
) that needs the output of t1
. Such a flow would look something like this:
id: each-sequential-nested
namespace: company.team
tasks:
- id: each
type: io.kestra.plugin.core.flow.EachSequential
value: '["s1", "s2", "s3"]'
tasks:
- id: t1
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }} > {{ taskrun.value }}"
- id: t2
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }} > {{ (get outputs.t1 taskrun.value).value }} > {{ taskrun.startDate }}"
- id: end
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }}"
In this case, you would need to use {{ (get outputs.t1 taskrun.value).value }}
, which means give me from outputs.t1
the index results from taskrun.value
.
With Flowable Task nested.
If you have many Flowable Tasks, it can be complex to use the get
function, and moreover, the taskrun.value
is only available during the direct task from each. If you have any Flowable Tasks after, the taskrun.value
of the first iteration will be lost (or overwritten). To deal with this, we have included the parent
& parents
vars.
This is illustrated in the flow below:
id: each-switch
namespace: company.team
tasks:
- id: t1
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }} > {{ taskrun.startDate }}"
- id: 2_each
type: io.kestra.plugin.core.flow.EachSequential
value: '["a", "b"]'
tasks:
# Switch
- id: 2-1_switch
type: io.kestra.plugin.core.flow.Switch
value: "{{ taskrun.value }}"
cases:
a:
- id: 2-1_switch-letter-a
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }}"
b:
- id: 2-1_switch-letter-b
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }}"
- id: 2-1_each
type: io.kestra.plugin.core.flow.EachSequential
value: '["1", "2"]'
tasks:
- id: 2-1-1_switch
type: io.kestra.plugin.core.flow.Switch
value: "{{ taskrun.value }}"
cases:
1:
- id: 2-1-1_switch-number-1
type: io.kestra.plugin.core.debug.Return
format: "{{ parents[0].taskrun.value }}"
2:
- id: 2-1-1_switch-number-2
type: io.kestra.plugin.core.debug.Return
format: "{{ parents[0].taskrun.value }} {{ parents[1].taskrun.value }}"
- id: 2_end
type: io.kestra.plugin.core.debug.Return
format: "{{ task.id }} > {{ taskrun.startDate }}"
As you can see, the parent
will give direct access to the first parent output and the value of the current one, while the parents[INDEX]
lets go you deeper down the tree.
In the task 2-1-1_switch-number-2
:
{{ taskrun.value }}
: mean the value of the task2-1-1_switch
{{ parents[0].taskrun.value }}
or{{ parent.taskrun.value }}
: mean the value of the task2-1_each
{{ parents[1].taskrun.value }}
: mean the value of the task2-1_switch
{{ parents[2].taskrun.value }}
: mean the value of the task2_each
vars
firstDefined
First defined variables
Return the first defined variables or throw an exception if no variables are defined.
{{ firstDefined outputs.task1.uri outputs.task2.uri }}
eval
Evaluate a handlebars expression
Evaluate a handlebars expression at runtime based on the whole context.
Mostly useful for Lookup in current child's tasks tree and dynamic tasks.
{{ eval 'outputs.first.[{{taskrun.value}}].value' }}
firstDefinedEval
First defined evaluation
First defined evaluates a handlebars expression at runtime based on the whole context or throws an exception if no variables are defined.
Mostly useful for Lookup in current child's tasks tree and dynamic tasks.
{{ firstDefined 'outputs.first.value' 'outputs.first.[{{taskrun.value}}].value' }}
get
get an element for an array or map by key
{{ get object ["key"] }}
- get on
object
type map, the key atkey
- get on
object
type array, the index atkey
Mostly useful for Lookup in current child's tasks tree and dynamic tasks.
{{ get outputs 'first' }}
Was this page helpful?