Functions

Built-in and custom functions available in Go templates.

Overview

Go provides a limited set of built-in template functions. Vela provides a number of additional, predefined functions to utilize in templates.

Built-in Functions

See Go template Functions for a list of built-in functions.

Example

A function call:

{{ printf "%q" "output" }}

A function call whose final argument comes from the previous command:

{{ "output" | printf "%q" }}

Custom Functions

Sprig

Sprig provides over 100 additional template functions. Please refer to the original Sprig function documentation.

To note, the env and expandenv functions are not available in Vela.

toYaml

The toYaml function is intended to ease working with passing and rendering YAML content in Vela templates.

Example

.vela.yml

version: "1"
templates:
  - name: golang
    source: github.com/<org>/<repo>/path/to/file/<template>.yml
    type: github

steps:
  - name: sample
    template:
      name: golang
      vars:
        ruleset:
          event: [ push, pull_request ]
          branch: [ main ]

github.com/<org>/<repo>/path/to/file/<template>.yml

metadata:
  template: true

steps:
  - name: install
    commands:
      - test
    image: alpine
    ruleset:
      {{- toYaml .ruleset | nindent 6 }}

With the pipeline and template above in place, the final resulting pipeline would render as follows:

version: "1"
steps:
  - name: sample_install
    commands:
      - test
    image: alpine
    ruleset:
      event: [ push, pull_request ]
      branch: [ main ]

vela

The vela function provides the convenience of accessing Vela environment variables within your Vela templates. See its dedicated platform vars page for more info.

Last modified September 16, 2022: chore: use main as default (#324) (400aa851)