Expression

Expressions can be used to configure actions. They are lazy evaluated - right before invoking action. An expression evaluates to a typed value. Terrabuild supports following types:

  • Nothing
  • String
  • Boolean
  • Number
  • List
  • Map

Type is inferred and the sole consequence of the evaluation.

Types

Nothing

Value for no value (pun intended). Similar to void or None in other languages.

Literal is nothing.

String

A string is a sequence of characters. A string starts with " and ends with ":

  • "this is a string"
  • ""

Boolean

Either literal true or false.

Number

A number is a 32 bits signed integer:

  • 42
  • -123456

List

A list is an ordered sequence of values - values can be of different types:

  • [ 1 2 3 ]
  • [ 1 "value" 42]

As Terrabuild does not use comma separator, it’s better to format like this:

[ 1
  2
  3 ]

[ 1
  "value"
  42 ]

Map

A map is a collection of named values. Name is always an identifier. Values can be of different types.

{ 
  configuration: "Release"
  max: 42
}

{ a: 1 b: 2 }

As Terrabuild does not use comma separator, it’s better to format like this:

{ configuration: "Release"
  max: 42 }

{ a: 1
  b: 2 }

Functions

Functions can be applied on values. Functions take a tuple as argument (param1, param2) which can be built from aforementioned primitives.

String

FunctionDescriptionUsageResult
+concatenate two strings"Hello" + "world""Hello world"
trimremove leading and trailing spacestrim(" Hello world ")"Hello world"
upperconvert string to upper caseupper("Hello world")"HELLO WORLD"
lowerconvert string to lower caselower("Hello WORLD")"hello world"
versionget unique hash for project identifier.version("/src/apps/webapp")159E0A6A3AEDE57BC71A3BD51037778423C7579FBAEC9CE93D47AB6BE3A9E786
replacereplace in string.replace("Hello world", "world", "Terrabuild")Hello Terrabuild
formatformat a string.format("Hello", " ", "Terrabuild")Hello Terrabuild

Number

FunctionDescriptionUsageResult
+add two numbers5 + 27
-substract two numbers5 - 23

List

FunctionDescriptionUsageResult
ItemGet item at position: error if index is not valid[1 2 3].12
TryItemTry get item at position: nothing if index is not valid[1 2 3].?4nothing
CountGet number of element of listcount([1 2 3])3
+Concatenate two lists[1 2 3] + [4 5 6][1 2 3 4 5 6]

Map

FunctionDescriptionUsageResult
ItemGet named item (using identifier): error if index is not valid{ a: 1 b: 2 }.b2
TryItemTry get named item (using identifier): nothing if index is not valid{ a: 1 b: 2 }.?cnothing
CountGet number of element of mapcount({ a: 1 b: 2 })2
+Merge two maps{ a: 1 b: 1} + { b: 2 c: 2}{ a: 1 b: 2 c: 2}

Variable

A variable can be used in an expression. A variable starts with $ followed by an identifier literal:

  • $configuration
  • $terrabuild_project

When expression is evaluated, the variable is replaced with its value (provided either in configuration block or command line). A variable must be defined to evaluate correctly the expression.

Generic

FunctionDescriptionUsageResult
Nottrue if falsy (nothing or false)!falsetrue
Equalcompares two values for equality"env" = "prod"false
NotEqualcompares two values for inequality"env" != "prod"true
Null-Coalescereturn value or alternate value if nothingnothing ?? 4242
Ternary Conditionalchecks boolean value and returns truthy or falsy valuenothing ? 42 : 666666

Composition

Expressions can be composed: lower("ghcr.io/" + $org + $terrabuild_project)

Predefined variables

Several variables are defined and available when evaluating steps:

NameDescription
terrabuild_projectName of current project
terrabuild_targetName of current target
terrabuild_hashHash of current project
terrabuild_configurationName of current configuration
terrabuild_branch_or_tagName of current branch or tag
terrabuild_head_commitHead commit commit
terrabuild_retrytrue if build is retried.
terrabuild_forcetrue if build is forced.
terrabuild_citrue if build is running in known CI.
terrabuild_debugtrue if debug is enabled.
terrabuild_tagTag provided by user or nothing.
terrabuild_noteNote provided by user or nothing.
Last updated on