2022-07-17 16:25:56 +00:00
|
|
|
# Advanced YAML syntax
|
|
|
|
|
|
|
|
## Anchors & aliases
|
|
|
|
|
|
|
|
You can use [YAML anchors & aliases](https://yaml.org/spec/1.2.2/#3222-anchors-and-aliases) as variables in your pipeline config.
|
|
|
|
|
|
|
|
To convert this:
|
|
|
|
```yml
|
|
|
|
pipeline:
|
|
|
|
test:
|
|
|
|
image: golang:1.18
|
2022-07-18 21:08:13 +00:00
|
|
|
commands: go test ./...
|
2022-07-17 16:25:56 +00:00
|
|
|
build:
|
|
|
|
image: golang:1.18
|
2022-07-18 21:08:13 +00:00
|
|
|
commands: build
|
2022-07-17 16:25:56 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Just add a new section called **variables** like this:
|
|
|
|
|
|
|
|
```diff
|
|
|
|
+variables:
|
|
|
|
+ - &golang_image 'golang:1.18'
|
|
|
|
|
|
|
|
pipeline:
|
|
|
|
test:
|
|
|
|
- image: golang:1.18
|
|
|
|
+ image: *golang_image
|
2022-07-18 21:08:13 +00:00
|
|
|
commands: go test ./...
|
2022-07-17 16:25:56 +00:00
|
|
|
build:
|
|
|
|
- image: golang:1.18
|
|
|
|
+ image: *golang_image
|
2022-07-18 21:08:13 +00:00
|
|
|
commands: build
|
2022-07-17 16:25:56 +00:00
|
|
|
```
|
|
|
|
|
2022-09-17 07:00:40 +00:00
|
|
|
<!--
|
|
|
|
TODO(1192): Support YAML override and extension
|
|
|
|
|
2022-07-17 16:25:56 +00:00
|
|
|
## Example of YAML override and extension
|
|
|
|
|
|
|
|
```yml
|
|
|
|
variables:
|
|
|
|
&some-plugin-settings
|
2022-09-17 07:00:40 +00:00
|
|
|
target: dist
|
|
|
|
recursive: false
|
|
|
|
try: true
|
2022-07-17 16:25:56 +00:00
|
|
|
|
|
|
|
pipelines:
|
|
|
|
develop:
|
|
|
|
name: Build and test
|
|
|
|
image: some-plugin
|
|
|
|
settings: *some-plugin-settings
|
|
|
|
when:
|
|
|
|
branch: develop
|
|
|
|
|
2022-09-17 07:00:40 +00:00
|
|
|
main:
|
2022-07-17 16:25:56 +00:00
|
|
|
name: Build and test
|
|
|
|
image: some-plugin
|
|
|
|
settings:
|
|
|
|
<<: *some-plugin-settings
|
|
|
|
try: false # replacing original value from `some-plugin-settings`
|
|
|
|
ongoing: false # adding a new value to `some-plugin-settings`
|
|
|
|
when:
|
|
|
|
branch: main
|
|
|
|
```
|
2022-09-17 07:00:40 +00:00
|
|
|
-->
|