Expression Condition Syntax

Each step in codefresh.yml file can contain expression conditions that must be satisfied for the step to execute.

This is a small example of where an expression condition 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 expression condition 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: “”
  • String with content = true
  • Empty string = false
  • String with contenet = true
String comparison is lexicographic.
Number True: 5
True: 3.4
True: 1.79E+308
  • Any number other than 0 = true.
  • 0 = false
Boolean True: true
False: false
  • True = true
  • False = false
Null False: null Always false

Variables

  • You can use the User Provided variables as explained in the Variables article.
  • Each step creates a variable based on the name of the variable. A standard variable that always exists is main_clone. You can then use the members of each variable.
  • To access variables that have a non-standard (i.e. only alphanumeric and _ characters) names, use the Variable() function.

Members

Variables that are created by steps can have members. The members depend on the variable type.

Step Type Members
All step types
  • name
  • type
  • description
  • failFast
  • workingDirectory
  • environment
Freestep -
Build
  • dockerfile
  • imageName
  • tag
  • buildArguments
Git-clone
  • revision
  • credentials
  • repo
  • imageId
Composition
  • compositionCandidates
  • composition
  • startImmediately
  • environmentName
  • assets
  • compositionVariables
Push
  • candidate
  • tag
  • registry
  • credentials
  • imageId
  • To access members that have a non-standard (i.e., only alphanumeric and _ characters) names, use the Member() function.

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
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’)