Multiline
Example Go template with multiline strings.
We recommend reviewing Go Templates documentation before attempting to create a template.
If you’re new to YAML we also recommend reviewing the YAML 1.2 spec for validation on syntax.
Overview
From YAML Spec Scalars:
|
- In Scalar literals, newlines are preserved
# Below YAML was taken from spec literal example
--- |
\//||\/||
// || ||__
Tip:
For information on more types of scalars read the spec informationSample
Let’s take a look at using a conditional with a variable in a template:
metadata:
template: true
steps:
{{ .test }}
- name: build
commands:
- go build
environment:
CGO_ENABLED: '0'
GOOS: linux
image: golang:latest
pull: always
ruleset:
event: [ push, pull_request ]
The caller of this template could look like:
version: "1"
templates:
- name: sample
source: github.com/<org>/<repo>/path/to/file/<template>.yml
type: github
steps:
- name: golang
template:
name: sample
vars:
test: |
- name: test
commands:
- go test ./...
image: golang:latest
pull: always
ruleset:
event: [ push, pull_request ]
Which means the compiled pipeline for execution on a worker is:
version: "1"
steps:
- name: sample_test
commands:
- go test ./...
image: golang:latest
pull: always
ruleset:
event: [ push, pull_request ]
- name: sample_build
commands:
- go build
image: golang:latest
pull: always
ruleset:
event: [ push, pull_request ]
Last modified April 5, 2022: feat: add docs for new render inline option (#291) (cc97f122)