Go template syntax, Sprig functions, regex extraction, and JavaScript expressions in OrchStep
OrchStep uses Go templates with Sprig functions for variable interpolation, and supports JavaScript expressions via the Goja VM for complex logic.
Go Template Syntax
Expressions are enclosed in {{ }}:
steps :
- func : shell
do : echo "Deploying {{ vars.version }} to {{ vars.environment }}" COPY
Variable Access
Pattern Description {{ vars.name }}Workflow variable {{ steps.step_name.field }}Step output {{ env.VAR_NAME }}Environment variable {{ result.output }}Current step result (in outputs:) {{ loop.item }}Current loop item {{ loop.index }}Current loop index (zero-based)
Conditionals in Templates
do : |
echo "Deploying to {{ vars.env }}"
{{- if eq vars.env "production" }}
echo "Extra production checks enabled"
{{- end }} COPY
Iteration in Templates
do : |
{{ range vars.servers }}
echo "Server: {{ . }}"
{{ end }} COPY
Sprig Functions
OrchStep includes Sprig v3 with 100+ utility functions.
String Functions
Function Example Result upper{{ "hello" | upper }}HELLOlower{{ "HELLO" | lower }}hellotitle{{ "hello world" | title }}Hello Worldtrim{{ " hello " | trim }}hellotrimSuffix{{ "hello.txt" | trimSuffix ".txt" }}helloreplace{{ "hello" | replace "l" "r" }}herrocontains{{ contains "hello" "ell" }}truehasPrefix{{ hasPrefix "hello" "hel" }}truehasSuffix{{ hasSuffix "hello" "llo" }}truerepeat{{ "ab" | repeat 3 }}abababsubstr{{ substr 0 5 "hello world" }}hellotrunc{{ trunc 5 "hello world" }}hellocamelcase{{ "my-service" | camelcase }}myServicesnakecase{{ "myService" | snakecase }}my_servicekebabcase{{ "myService" | kebabcase }}my-servicesplit{{ split "," "a,b,c" }}list [a, b, c] join{{ list "a" "b" "c" | join "," }}a,b,c
Math Functions
Function Example Result add{{ add 1 2 }}3sub{{ sub 10 3 }}7mul{{ mul 3 4 }}12div{{ div 10 3 }}3mod{{ mod 10 3 }}1max{{ max 5 10 }}10min{{ min 5 10 }}5ceil{{ ceil 1.5 }}2floor{{ floor 1.5 }}1
List Functions
Function Description firstFirst element of a list lastLast element of a list restAll elements except first appendAdd element to end of list concatMerge two lists uniqRemove duplicate elements hasCheck if list contains element withoutRemove elements from list sliceSub-list extraction reverseReverse list order
Dictionary Functions
Function Description getGet value by key setSet value for key hasKeyCheck if key exists keysGet all keys valuesGet all values pickSelect subset of keys omitExclude subset of keys mergeMerge dictionaries
Type Conversion
Function Description atoiString to integer toStringConvert to string toJsonSerialize to JSON string toPrettyJsonSerialize to formatted JSON fromJsonParse JSON string to object toYamlSerialize to YAML string
Date/Time Functions
Function Example nowCurrent time date{{ now | date "2006-01-02" }}dateModify{{ now | dateModify "+24h" }}unixEpoch{{ now | unixEpoch }}
Encoding Functions
Function Description b64encBase64 encode b64decBase64 decode sha256sumSHA-256 hash urlqueryURL-encode string uuidv4Generate UUID v4
Logic Functions
Function Example default{{ vars.port | default 8080 }}empty{{ empty vars.name }}coalesce{{ coalesce vars.a vars.b "fallback" }}ternary{{ ternary "yes" "no" (eq vars.env "prod") }}
Regex Functions
Function Description Example regexMatchTest if string matches pattern {{ regexMatch "v[0-9]+" vars.version }}regexFindExtract first capture group {{ result.output | regexFind "ID=(.+)" }}regexFindAllExtract all matches {{ regexFindAll "[0-9]+" result.output -1 }}regexReplaceAllReplace all matches {{ regexReplaceAll "[0-9]+" result.output "X" }}
Semantic Versioning
Function Example semver{{ semver "1.2.3" }} -- parse to semver objectsemverCompare{{ semverCompare ">=1.2.0" vars.version }} -- compare versions
Quoting values for the shell
Template values are inserted into func: shell commands as raw text. Any value
you don't fully control (a --var, an MCP tool argument, an HTTP response, a
dashboard run form) could contain shell syntax such as $(...) or ;. Pipe it
through shellquote (alias shq, v0.15.0+) to render it as one inert POSIX
shell word:
- name : checkout
func : shell
do : git checkout {{ vars.branch | shellquote }} COPY
Value Renders as mainmain (safe words stay bare)feature/x y'feature/x y'$(rm -rf ~)'$(rm -rf ~)', printed literally, never executedit's'it'\''s'
shellquote is also available in step outputs: and assert conditions.
Use regex in outputs: to extract structured data from command output:
steps :
- name : build
func : shell
do : |
echo "Building..."
echo "IMAGE=myapp:v1.2.3"
echo "DIGEST=sha256:abc123"
echo "SIZE=42MB"
outputs :
image : ' {{ result.output | regexFind "IMAGE=(.+)" }} '
digest : ' {{ result.output | regexFind "DIGEST=(.+)" }} '
size : ' {{ result.output | regexFind "SIZE=(.+)" }} ' COPY
# Extract key=value pair
output_field : ' {{ result.output | regexFind "KEY=(.+)" }} '
# Extract JSON field from mixed output
json_field : ' {{ result.data.field_name }} '
# Trim whitespace from output
clean_output : ' {{ result.output | trim }} '
# Default value if empty
safe_value : ' {{ result.output | default "unknown" }} '
# Extract version number
version : ' {{ result.output | regexFind "([0-9]+\\.[0-9]+\\.[0-9]+)" }} ' COPY
JavaScript Expressions
For complex logic that goes beyond Go templates, OrchStep supports JavaScript via the Goja VM. JavaScript is used in:
assert conditions (when no {{ }} wrapper)
retry.when conditions
loop.until conditions
transform function do: blocks
# Assert with JavaScript
- func : assert
args :
condition : ' steps.api.status_code >= 200 && steps.api.status_code < 300 '
# Retry with JavaScript condition
retry :
when : |
result.exit_code != 0 &&
!result.output.includes('invalid') &&
retry.attempt < 3
# Loop until with JavaScript
loop :
count : 30
until : ' steps.check.output.includes("READY") ' COPY
Best Practices
Use single quotes around Go template conditions to avoid YAML escaping: '{{ eq vars.x "y" }}'
Prefer regexFind over complex shell parsing for output extraction
Use default to provide fallback values: {{ vars.port | default 8080 }}
Use trim on extracted outputs to remove trailing newlines
Use JavaScript syntax for complex boolean logic (more readable than nested Go template and/or)