Carvel Logo

If Statements

Refer to Starlark if statement specification for details.

  • if
#@ if True:
test1: 123
test2: 124
#@ end
  • if (negative)
#@ if not True:
test1: 123
#@ end
  • single-node if
#@ if/end True:
test1: 123
  • if-else conditional
#@ if True:
test1: 123
#@ else:
test2: 124
#@ end
  • if-elif-else conditional
#@ if True:
test2: 123
#@ elif False:
test2: 124
#@ else:
test2: 125
#@ end
#@ test = 123
#@ if test > 100 and test < 200:
test1: 123
#@ elif test == 100 or test == 200:
test2: 124
#@ else:
test3: 125
#@ end
  • single line if
#@ passwd = "..."
test1: #@ passwd if passwd else assert.fail("password must be set")
  • implicit if
#@ passwd = "..."
test1: #@ passwd or assert.fail("password must be set")

(Help improve our docs: edit this page on GitHub)