Skip to main content

Template function reference

This page lists the functions for ${{ ... }} template expressions, with signatures and examples. For syntax, runtime context, operators, and safety rules, see Template expressions and functions.

Template syntax recap​

Write literal text normally and expressions inside ${{ ... }}. An expression can use variables, functions, operators, and the pipe (|):

https://login.microsoftonline.com/${{ inputs.azure-tenant-id }}/oauth2/v2.0/token

${{ inputs.azure-client-id }}

https://api.partnercenter.microsoft.com/v1${{ next | default("/invoices?size=1&offset=0") }}

${{ list.filter(
outputs.invoices,
fn(invoice) {
date.isBetween(
date.parse(invoice.billingPeriodStartDate),
date.toStartOfMonth(inputs.start-date),
date.toStartOfNextMonth(inputs.start-date)
)
}
) }}

${{ matrix.root-directory }}/${{ matrix.blob.name }}?${{ matrix.sas-token }}

Core logical and utility functions​

if​

(condition: boolean, then: () => any?, else: () => any?) -> any?

Evaluates then when condition is true, otherwise else. Only the selected branch is evaluated, as a plain expression or as a fn() { ... } callback, so the other branch cannot fail the expression.

${{ if(inputs.enabled, "on", "off") }}

With deferred branches:

${{
if(condition,
fn() { /* value when true */ },
fn() { /* value when false */ }
)
}}

and​

(...args: any?[]) -> boolean

Checks if all arguments are truthy. Evaluation runs left to right and stops at the first argument that is not truthy.

and() // false
and(true) // true
and(true, false) // false

An earlier argument can guard a later one. When outputs.etag is missing, this is false instead of a string.isEmpty error:

${{ and(outputs.etag != null, !string.isEmpty(outputs.etag)) }}
${{ and(truthy(inputs.start-date), truthy(inputs.end-date)) }}

or​

(...args: any?[]) -> boolean

Checks if any argument is truthy. Evaluation runs left to right and stops at the first truthy argument.

or() // false
or(true) // true
or(true, false) // true
or(false, false) // false
${{ or(inputs.filter, inputs.default-filter) }}

default​

(...args: any?[]) -> any

Returns the first truthy argument, or null when none is truthy. Evaluation runs left to right and stops at the first truthy value. In the pipe form value | default(fallback), the result is value when it is truthy and fallback otherwise.

default() // null
default(null) // null
default(null, 2) // 2
${{ default(inputs.next, "/invoices?size=1&offset=0") }}

simplify​

(value: any) -> any

Unwraps nested single-element lists and returns the first value that is not a single-element list. Non-list values are returned unchanged.

simplify([1]) // 1
simplify([[[1]]]) // 1
simplify([[[1, 2]]]) // [1, 2]

Use it for API outputs that sometimes return nested lists:

${{ simplify(outputs.items) }}

truthy​

(a: any) -> boolean

Returns whether a value is truthy.

  • Truthy: any non-empty string, a number other than 0, a non-empty array, a non-empty object, and true.
  • Falsy: null, false, 0, "", an empty list, and an empty object.
truthy(1) // true
truthy("") // false
truthy(truthy(truthy(1))) // true
${{ if(truthy(inputs.token), "has token", "no token") }}

now​

() -> DateTime

Returns the run reference time: one UTC timestamp, in whole seconds, captured when the workflow run is admitted.

  • Every job, retry, and planning step of the run gets the same value. A correction reuses the reference time of the run it corrects.
  • now() takes no arguments. Combine it with the date helpers for offsets.
  • It fails with a clear error when a run has no reference time, for example a run that started before now() was available.
  • During draft validation and the Review check, now() uses the review clock that the review response reports, truncated to whole seconds.
now() // "2026-09-14T12:00:00Z"
date.addHour(now(), -1) // "2026-09-14T11:00:00Z"
date.toStartOf(now(), "day") // "2026-09-14T00:00:00Z"
date.addDay(date.toStartOf(now(), "day"), -30) // "2026-08-15T00:00:00Z"

The previous 30 completed days:

start: ${{ date.addDay(date.toStartOf(now(), "day"), -30) }}
end: ${{ date.toStartOf(now(), "day") }}

Call now() directly in each input. An input cannot reference another input whose value is an expression, so ${{ date.addDay(inputs.end, -30) }} fails when end is an expression.

For a scheduled run, now() is the time the run was admitted, not the cron time. When a window must follow the intended schedule period even if the run starts late, use the timestamp input that the schedule injects, such as inputs.scheduled_time.

Numeric helpers​

num.max​

(...n: number[]) -> number

Maximum of all numbers passed.

num.max(3) // 3
num.max(3, 5) // 5
num.max(3, 5, 1) // 5
${{ num.max(inputs.min-page-size, 1) }}

num.min​

(...n: number[]) -> number

Minimum of all numbers passed.

num.min(3) // 3
num.min(3, 5) // 3
num.min(3, 5, 1) // 1
${{ num.min(inputs.page-size, 1000) }}

Lists and anonymous functions​

fn​

fn(item) { expression }

Syntax for an anonymous callback, not a standalone runtime function. The callback body is the result. Do not add a return keyword.

fn(item) { item.total > 0 }
${{
list.filter(
outputs.invoices,
fn(item) {
item.total > 0
}
)
}}

list.filter​

(items: any[], predicate: (item: any) -> any) -> any[]

Keeps the list items for which the predicate returns a truthy value. The list comes first and the predicate second.

list.filter([1, 2, 3], fn(a) { a >= 2 }) // [2, 3]

With objects:

${{
list.filter(
outputs.invoices,
fn(invoice) {
invoice.total > 0
}
)
}}

For all list.* helpers, see the function catalog.

String helpers​

The string.* helpers take plain strings and return strings, booleans, or lists as noted.

string.contains​

(s: string, sub: string) -> boolean

Checks if s contains sub.

string.contains("hello", "ell") // true
${{ string.contains(inputs.email, "@") }}

string.endsWith​

(s: string, suffix: string) -> boolean

Checks if s ends with suffix.

string.endsWith("hello world", "world") // true

string.format​

(format: string, ...args: any[]) -> string

Replaces numbered placeholders such as {0} and {1} with the supplied values.

string.format("Hello, {0}!", "world") // "Hello, world!"
string.format("{0}, {1}, {2}", 1, 2, 3) // "1, 2, 3"
${{ string.format("Invoice {0} for {1}", invoice.id, invoice.customerName) }}

string.jsonEncode​

(value: string) -> string

Encodes one string as a JSON string value. The result includes the surrounding quotes and escapes embedded quotes and control characters.

string.jsonEncode("a\"b") // "a\"b"

Use it when an Extractor request body needs a conditional JSON property, so that a pagination token cannot break the request JSON. It takes one string, so a list output such as outputs.keys is refused. Join a list first, for example list.join(outputs.keys, ",").

string.isEmpty​

(s: string) -> boolean

Checks if a string is empty.

string.isEmpty("") // true
string.isEmpty("foo") // false

string.len​

(s: string) -> number

Length of a string, counted in characters.

string.len("foo") // 3
string.len("マルチバイト文字") // 8
string.len("🤔🤔🤔") // 3

string.padEnd​

(s: string, length: number, character: string) -> string

Pads the end of s until it reaches length.

string.padEnd("foo", 5, " ") // "foo "

string.padStart​

(s: string, length: number, character: string) -> string

Pads the start of s until it reaches length.

string.padStart("foo", 5, " ") // " foo"

string.repeat​

(s: string, count: number) -> string

Repeats s count times.

string.repeat("a", 5) // "aaaaa"
string.repeat("マルチ", 2) // "マルチマルチ"

string.replace​

(s: string, old: string, new: string) -> string

Replaces every occurrence of old with new.

string.replace("hello world", "world", "tengu") // "hello tengu"
string.replace("foo foo foo", "foo", "bar") // "bar bar bar"

string.reverse​

(s: string) -> string

Reverses the characters in a string.

string.reverse("hello") // "olleh"

string.slice​

(s: string, start: number, end?: number) -> string

Extracts the substring from start (inclusive) to the optional end (exclusive). Without end, it returns the rest of the string.

string.slice("hello world", 6, 11) // "world"

string.split​

(s: string, delimiter: string) -> list

Splits s into a list using delimiter.

string.split("hello world", " ") // ["hello", "world"]

string.startsWith​

(s: string, prefix: string) -> boolean

Checks if s starts with prefix.

string.startsWith("hello world", "hello") // true

string.toLowercase​

(s: string) -> string

Lowercase version of s.

string.toLowercase("Foo") // "foo"
string.toLowercase("BAR") // "bar"

string.toUppercase​

(s: string) -> string

Uppercase version of s.

string.toUppercase("Foo") // "FOO"
string.toUppercase("bar") // "BAR"

string.trim​

(s: string) -> string

Removes whitespace from both ends.

string.trim(" foo ") // "foo"

string.trimEnd​

(s: string) -> string

Removes whitespace from the end only.

string.trimEnd(" foo ") // " foo"

string.trimStart​

(s: string) -> string

Removes whitespace from the start only.

string.trimStart(" foo ") // "foo "

Date and time helpers​

The date.* helpers work with a DateTime type.

Parsing dates and times​

date.parse​

(input: string, format: string?) -> DateTime

Parses a date and time string. Without format, the input must be RFC 3339. A format uses strftime codes.

date.parse("2014-11-28T21:00:09Z")
// "2014-11-28T21:00:09+00:00"

date.parse("2025年5月14日 15時9分33秒 +09", "%Y年%-m月%-d日 %-H時%-M分%-S秒 %#z")
// "2025-05-14T15:09:33+09:00"

date.parseDate​

(input: string, format: string) -> DateTime

Parses a date-only string. The time is set to midnight UTC.

date.parseDate("2014-11-28", "%F")
// "2014-11-28T00:00:00+00:00"

date.parseDate("2025年5月14日", "%Y年%m月%d日")
// "2025-05-14T00:00:00+00:00"

date.parseDateTime​

(input: string, format: string, timezone: string?) -> DateTime

Parses a date-time string with an explicit format. Without timezone, UTC is used.

date.parseDateTime("2014-11-28T21:00:09", "%FT%T")
// "2014-11-28T21:00:09+00:00"

date.parseDateTime(
"Thursday May 15, 2025; 3:45 pm",
"%A %B %d, %Y; %I:%M %P",
"America/New_York"
)
// "2025-05-15T15:45:00-04:00"

date.parseTime​

(input: string, format: string) -> DateTime

Parses a time-only string. The date is set to 0000-01-01 UTC.

date.parseTime("12:34", "%R")
// "0000-01-01T12:34:00+00:00"

date.parseTime("3:45 pm", "%I:%M %P")
// "0000-01-01T15:45:00+00:00"

Formatting and combining dates​

date.format​

(input: DateTime, format: string?) -> string

Formats a DateTime with strftime codes. Without format, it returns an RFC 3339-style string.

date.format(date.parse("2014-11-28T21:00:09Z"))
// "2014-11-28T21:00:09+00:00"

date.format(
date.parse("2025-05-14T15:09:33+09:00"),
"%Y年%-m月%-d日 %-H時%-M分%-S秒 %:::z"
)
// "2025年5月14日 15時9分33秒 +09"

date.setTime​

(left: DateTime, right: DateTime) -> DateTime

Returns the date from left with the time from right. The timezone of left is preserved.

date.setTime(
date.parse("2025-05-15T00:00:00Z"),
date.parseTime("12:34", "%R")
)
// "2025-05-15T12:34:00+00:00"

date.setTimezone​

(source: DateTime, timezone: string) -> DateTime

Changes only the timezone label. It does not adjust the clock time.

date.setTimezone(
date.parse("2025-05-15T12:34:56Z"),
"Europe/Amsterdam"
)
// "2025-05-15T12:34:56+02:00"

date.toTimezone​

(source: DateTime, timezone: string) -> DateTime

Converts source to the new timezone and adjusts the time.

date.toTimezone(
date.parse("2025-05-15T12:34:56Z"),
"Europe/Amsterdam"
)
// "2025-05-15T14:34:56+02:00"

Start-of-unit helpers​

Each helper returns a DateTime moved to the start of the unit and preserves the timezone:

  • date.toStartOfYear(source)
  • date.toStartOfNextYear(source)
  • date.toStartOfMonth(source)
  • date.toStartOfNextMonth(source)
  • date.toStartOfDay(source)
  • date.toStartOfNextDay(source)
  • date.toStartOfHour(source)
  • date.toStartOfNextHour(source)
  • date.toStartOfMinute(source)
  • date.toStartOfNextMinute(source)
  • date.toStartOfSecond(source)
  • date.toStartOfNextSecond(source)
date.toStartOfYear(date.parse("2025-03-21T12:34:56.7890+02:00"))
// "2025-01-01T00:00:00+02:00"

date.toStartOfNextMonth(date.parse("2025-03-21T12:34:56.7890+02:00"))
// "2025-04-01T00:00:00+02:00"

For a monthly range:

${{
date.isBetween(
invoiceDate,
date.toStartOfMonth(inputs.start-date),
date.toStartOfNextMonth(inputs.start-date)
)
}}

End-of-unit helpers​

Each helper moves to the end of the unit:

  • date.toEndOfYear(source)
  • date.toEndOfPreviousYear(source)
  • date.toEndOfMonth(source)
  • date.toEndOfPreviousMonth(source)
  • date.toEndOfDay(source)
  • date.toEndOfPreviousDay(source)
  • date.toEndOfHour(source)
  • date.toEndOfPreviousHour(source)
  • date.toEndOfMinute(source)
  • date.toEndOfPreviousMinute(source)
  • date.toEndOfSecond(source)
  • date.toEndOfPreviousSecond(source)
date.toEndOfMonth(date.parse("2025-03-21T12:34:56.7890+02:00"))
// "2025-03-31T23:59:59.999999999+02:00"

date.toEndOfPreviousMonth(date.parse("2025-03-21T12:34:56.7890+02:00"))
// "2025-02-28T23:59:59.999999999+02:00"

Date predicates​

date.isFirstDayOfMonth​

(input: DateTime) -> boolean

True if input is the first day of its month.

date.isFirstDayOfMonth(date.parse("2025-01-01T00:00:00Z")) // true

date.isLastDayOfMonth​

(input: DateTime) -> boolean

True if input is the last day of its month. Leap years are handled.

date.isLastDayOfMonth(date.parse("2024-02-29T00:00:00Z")) // true

date.isBetween​

(test: DateTime, start_boundary: DateTime, end_boundary: DateTime) -> boolean

True if test falls between the boundaries. start_boundary is inclusive and end_boundary is exclusive.

date.isBetween(
date.parse("2025-05-15T12:00:00Z"),
date.parse("2025-05-15T10:00:00Z"),
date.parse("2025-05-15T14:00:00Z")
)
// true

date.isBefore​

(test: DateTime, boundary: DateTime) -> boolean

True if test is strictly before boundary.

date.isBefore(
date.parse("2025-05-15T10:00:00Z"),
date.parse("2025-05-15T12:00:00Z")
) // true

date.isBefore(
date.parse("2025-05-15T12:00:00Z"),
date.parse("2025-05-15T12:00:00Z")
) // false

date.isAfter​

(test: DateTime, boundary: DateTime) -> boolean

True if test is strictly after boundary.

date.isEqual​

(test: DateTime, boundary: DateTime) -> boolean

True if test and boundary are the same instant, also in different timezones.

date.isEqual(
date.parse("2025-05-15T10:00:00Z"),
date.parse("2025-05-15T12:00:00+02:00")
) // true

date.earliest and date.latest​

  • date.earliest(...dates: DateTime[]) -> DateTime
  • date.latest(...dates: DateTime[]) -> DateTime
date.earliest(a, b) // returns the earliest of a, b
date.latest(a, b) // returns the latest of a, b

Date arithmetic​

These functions add to or subtract from a DateTime. The amount can be negative.

  • date.addYear(source: DateTime, amount: number) -> DateTime
  • date.addMonth(source: DateTime, amount: number) -> DateTime
  • date.addDay(source: DateTime, amount: number) -> DateTime
  • date.addHour(source: DateTime, amount: number) -> DateTime
  • date.addMinute(source: DateTime, amount: number) -> DateTime
  • date.addSecond(source: DateTime, amount: number) -> DateTime
date.addYear(date.parse("2023-03-15T10:30:00Z"), 2)
// "2025-03-15T10:30:00+00:00"

date.addMonth(date.parse("2023-01-15T10:00:00Z"), 1)
// "2023-02-15T10:00:00+00:00"

date.addDay(date.parse("2023-03-10T12:00:00Z"), 5)
// "2023-03-15T12:00:00+00:00"

date.addMinute(date.parse("2023-03-15T10:30:00Z"), 15)
// "2023-03-15T10:45:00+00:00"

Month and year arithmetic follows calendar normalization. If the original day does not exist in the target month, the overflow continues into the following month. For an exact reporting period, derive month boundaries with date.toStartOf* or date.toEndOf*.