Built-in Functions
Phobos provides the following built-in HCL functions that can be used in your pipeline templates and release lifecycle templates:
Collection functions
chunklist(list, chunk_size)
Divides a list into smaller sublists of a specified size, useful for batch processing or organizing data into groups.
chunklist(["a", "b", "c", "d"], 2)
# Returns: [["a", "b"], ["c", "d"]]
coalescelist(list1, list2, ...)
Returns the first list that contains at least one element, providing a fallback mechanism for empty lists.
coalescelist([], ["a", "b"])
# Returns: ["a", "b"]
compact(list)
Filters out null values and empty strings from a list, cleaning up sparse data structures.
compact(["a", "", "b", null])
# Returns: ["a", "b"]
concat(list1, list2, ...)
Merges multiple lists into a single list while preserving order, useful for combining data from different sources.
concat(["a"], ["b", "c"])
# Returns: ["a", "b", "c"]
contains(list, value)
Tests whether a list includes a specific value, returning true if found and false otherwise.
contains(["a", "b"], "a")
# Returns: true
distinct(list)
Removes duplicate values from a list while preserving the order of first occurrence.
distinct(["a", "b", "a"])
# Returns: ["a", "b"]
element(list, index)
Retrieves a specific item from a list using zero-based indexing, with wraparound for negative indices.
element(["a", "b", "c"], 1)
# Returns: "b"
flatten(list)
Converts nested lists into a single flat list, useful for processing hierarchical data structures.
flatten([["a"], ["b", "c"]])
# Returns: ["a", "b", "c"]
hasindex(list, index)
Checks whether a list has an element at the specified index position without causing an error.
hasindex(["a", "b"], 1)
# Returns: true
index(list, value)
Finds the position of a value in a list or retrieves a value from a map using a key.
index(["a", "b"], "b")
# Returns: 1
keys(map)
Extracts all keys from a map and returns them as a list, useful for iterating over map properties.
keys({a = 1, b = 2})
# Returns: ["a", "b"]
length(value)
Counts the number of elements in a collection (list, map, tuple, or string).
length(["a", "b", "c"])
# Returns: 3
lookup(map, key, default)
Safely retrieves a value from a map by key, returning a default value if the key doesn't exist.
lookup({a = 1}, "b", 0)
# Returns: 0
merge(map1, map2, ...)
Combines multiple maps into one, with later maps overriding values from earlier ones for duplicate keys.
merge({a = 1}, {b = 2})
# Returns: {a = 1, b = 2}
range(start, limit, step)
Creates a sequence of numbers from start to limit (exclusive) with a specified step increment.
range(1, 4, 1)
# Returns: [1, 2, 3]
reverse(list)
Returns a new list with elements in reverse order, useful for processing data backwards.
reverse(["a", "b", "c"])
# Returns: ["c", "b", "a"]
slice(list, start_index, end_index)
Extracts a portion of a list from start index to end index (exclusive), similar to array slicing.
slice(["a", "b", "c"], 1, 3)
# Returns: ["b", "c"]
sort(list)
Arranges list elements in ascending order, useful for organizing data alphabetically or numerically.
sort(["c", "a", "b"])
# Returns: ["a", "b", "c"]
values(map)
Extracts all values from a map and returns them as a list, complementing the keys function.
values({a = 1, b = 2})
# Returns: [1, 2]
zipmap(keyslist, valueslist)
Creates a map by pairing elements from a keys list with corresponding elements from a values list.
zipmap(["a", "b"], [1, 2])
# Returns: {a = 1, b = 2}
Set functions
setintersection(sets...)
Finds elements that exist in all provided sets, useful for identifying common values across multiple collections.
setintersection(["a", "b"], ["b", "c"])
# Returns: ["b"]
setproduct(sets...)
Generates all possible combinations by taking one element from each set, creating a Cartesian product.
setproduct(["a"], [1, 2])
# Returns: [["a", 1], ["a", 2]]
setsubtract(set1, set2)
Returns elements from the first set that are not present in the second set, performing set difference.
setsubtract(["a", "b"], ["b"])
# Returns: ["a"]
setunion(sets...)
Merges multiple sets into one, removing duplicates while preserving unique elements from all sets.
setunion(["a"], ["b", "a"])
# Returns: ["a", "b"]
sethaselement(set, value)
Tests whether a set contains a specific element, providing a safe way to check membership.
sethaselement(["a", "b"], "a")
# Returns: true
setsymmetricdifference(set1, set2)
Returns elements that exist in either set but not in both, finding the symmetric difference.
setsymmetricdifference(["a", "b"], ["b", "c"])
# Returns: ["a", "c"]
String functions
chomp(string)
Removes trailing newline characters and carriage returns from a string, useful for cleaning input data.
chomp("hello\n")
# Returns: "hello"
format(string, values...)
Creates formatted strings using printf-style placeholders, enabling dynamic string construction.
format("Hello %s", "world")
# Returns: "Hello world"
formatlist(format, values...)
Applies a format string to each element in a list, creating a list of formatted strings.
formatlist("item-%s", ["a", "b"])
# Returns: ["item-a", "item-b"]
indent(num_spaces, string)
Adds a specified number of spaces to the beginning of each line in a multi-line string.
indent(2, "line1\nline2")
# Returns: " line1\n line2"
join(separator, list)
Concatenates list elements into a single string using a specified delimiter between elements.
join(",", ["a", "b", "c"])
# Returns: "a,b,c"
lower(string)
Converts all characters in a string to lowercase, useful for case-insensitive comparisons.
lower("HELLO")
# Returns: "hello"
regex(string, pattern)
Extracts the first substring that matches a regular expression pattern from the input string.
regex("hello123", "[0-9]+")
# Returns: "123"
regexall(string, pattern)
Finds all substrings that match a regular expression pattern and returns them as a list.
regexall("a1b2c3", "[0-9]")
# Returns: ["1", "2", "3"]
regex_replace(string, pattern, replacement)
Replaces all occurrences of a regular expression pattern with a replacement string.
regex_replace("hello123", "[0-9]+", "world")
# Returns: "helloworld"
replace(string, substr, replacement)
Substitutes all occurrences of a substring with a replacement string, performing literal matching.
replace("hello", "ll", "xx")
# Returns: "hexxo"
split(separator, string)
Divides a string into a list of substrings using a specified delimiter character or string.
split(",", "a,b,c")
# Returns: ["a", "b", "c"]
strlen(string)
Calculates the number of characters in a string, including spaces and special characters.
strlen("hello")
# Returns: 5
strrev(string)
Reverses the order of characters in a string, useful for certain text processing operations.
strrev("hello")
# Returns: "olleh"
substr(string, offset, length)
Extracts a portion of a string starting at a specified position for a given number of characters.
substr("hello", 1, 3)
# Returns: "ell"
title(string)
Capitalizes the first letter of each word in a string, creating title case formatting.
title("hello world")
# Returns: "Hello World"
trim(string, cutset)
Removes specified characters from both the beginning and end of a string.
trim("!!hello!!", "!")
# Returns: "hello"
trimprefix(string, prefix)
Removes a specified prefix from the beginning of a string if it exists.
trimprefix("hello", "he")
# Returns: "llo"
trimspace(string)
Removes whitespace characters (spaces, tabs, newlines) from both ends of a string.
trimspace(" hello ")
# Returns: "hello"
trimsuffix(string, suffix)
Removes a specified suffix from the end of a string if it exists.
trimsuffix("hello", "lo")
# Returns: "hel"
upper(string)
Converts all characters in a string to uppercase, useful for standardizing text format.
upper("hello")
# Returns: "HELLO"
Numeric functions
abs(number)
Returns the absolute value of a number, removing the negative sign if present.
abs(-5)
# Returns: 5
ceil(number)
Rounds a number up to the nearest integer, always rounding towards positive infinity.
ceil(4.2)
# Returns: 5
floor(number)
Rounds a number down to the nearest integer, always rounding towards negative infinity.
floor(4.8)
# Returns: 4
log(number, base)
Calculates the logarithm of a number using the specified base, useful for mathematical operations.
log(8, 2)
# Returns: 3
max(number1, number2, ...)
Returns the largest value from a set of numbers, useful for finding maximum values.
max(1, 5, 3)
# Returns: 5
min(number1, number2, ...)
Returns the smallest value from a set of numbers, useful for finding minimum values.
min(1, 5, 3)
# Returns: 1
parseint(string, base)
Converts a string representation of a number to an integer using the specified base (2-36).
parseint("15", 10)
# Returns: 15
pow(number, power)
Raises a number to a specified power, performing exponentiation operations.
pow(2, 3)
# Returns: 8
signum(number)
Returns the sign of a number: -1 for negative, 0 for zero, and 1 for positive values.
signum(-5)
# Returns: -1