Condition Expression Syntax
Condition expressions can be included in each step in your codefresh.yml, and must be satisfied for the step to execute.
Each step in codefresh.yml
file can contain conditions expressions that must be satisfied for the step to execute.
This is a small example of where a condition expression can be used:
YAML
step-name:
description: Step description
image: image/id
commands:
- bash-command1
- bash-command2
when:
condition:
all:
executeForMasterBranch: "'${{CF_BRANCH}}' == 'master'"
A condition expression is a basic expression that is evaluated to true/false (to decide whether to execute or not to execute), and can have the following syntax:
Types
Type | True/False Examples | True/False |
---|---|---|
String | True: “hello” False: “” |
|
Number | True: 5 True: 3.4 True: 1.79E+308 |
|
Boolean | True: true False: false |
|
Null | False: null | Always false |
Variables
You can use the User Provided variables as explained in the Variables documentation including the variables exposed by each individual pipeline step.
Unary Operators
Operator | Operation |
---|---|
- |
Negation of numbers |
! |
Logical NOT |
Binary Operators
Operator | Operation |
---|---|
Add, String Concatenation | + |
Subtract | - |
Multiply | * |
Divide | / |
Modulus | % |
Logical AND | && |
Logical OR | || |
Comparisons
Operator | Operation |
---|---|
== |
Equal to |
!= |
Not equal to |
> |
Greater than |
>= |
Greater than or equal |
< |
Less than |
<= |
Less than or equal |
Functions
Function Name | Parameters | Return value | Example |
---|---|---|---|
String | 0: number or string | String of input value. | String(40) == '40' |
Number | 0: number or string | Number of input value. | Number('50') == 50 Number('hello') is invalid |
Boolean | 0: number or string | Boolean of input value. | Boolean('123') == true Boolean('') == false Boolean(583) == true Boolean(0) == false |
round | 0: number | Rounded number. | round(1.3) == 1 round(1.95) == 2 |
floor | 0: number | Number rounded to floor. | floor(1.3) == 1 floor(1.95) == 1 |
upper | 0: string | String in upper case. | upper('hello') == 'HELLO' |
lower | 0: string | String in lower case. | lower('BYE BYE') == 'bye bye' |
trim | 0: string | Trimmed string. | trim(" abc ") == "abc" |
trimLeft | 0: string | Left-trimmed string. | trimLeft(" abc ") == "abc " |
trimRight | 0: string | Right-trimmed string. | trimRight(" abc ") == " abc" |
replace | 0: string - main string 1: string - substring to find 2: string - substring to replace |
Replace all instances of the sub-string (1) in the main string (0) with the sub-string (2). | replace('hello there', 'e', 'a') == 'hallo thara' |
substring | 0: string - main string 1: string - index to start 2: string - index to end |
Returns a sub-string of a string. | substring("hello world", 6, 11) == "world" |
length | string | Length of a string. | length("gump") == 4 |
includes | 0: string - main string 1: string - string to search for |
Whether a search string is located within the main string. | includes("codefresh", "odef") == true |
indexOf | 0: string - main string 1: string - string to search for |
Index of a search string if it is found inside the main string | indexOf("codefresh", "odef") == 1 |
match | 0: string - main string 1: string - regular expression string, JS style (Note: in JS strings, the backslash \ is an escape character so in order to use a literal backslash, you need to escape it. For example: "^\\d+$" instead of "^\d+$" )2: boolean - ignore case |
Search for a regular expression inside a string, ignoring or not ignoring case | match("hello there you", "..ll.", false) == true match("hello there you", "..LL.", false) == false match("hello there you", "hell$", true) == false match("hello there you", "^hell", true) == true match("hello there you", "bye", false) == false |
Variable | string | Search for the value of a variable | Variable('some-clone') |
Member | 0: string - variable name 1: string - member name |
Search for the value of a variable member | Member('some-clone', 'working-directory') |