woodpecker/docs/docs/20-usage/35-advanced-yaml-syntax.md
6543 c3eed4ec01
Fix docs (#1035)
Co-authored-by: Anbraten <anton@ju60.de>
2022-07-18 23:08:13 +02:00

1.2 KiB

Advanced YAML syntax

Anchors & aliases

You can use YAML anchors & aliases as variables in your pipeline config.

To convert this:

pipeline:
  test:
    image: golang:1.18
    commands: go test ./...
  build:
    image: golang:1.18
    commands: build

Just add a new section called variables like this:

+variables:
+  - &golang_image 'golang:1.18'

 pipeline:
   test:
-    image: golang:1.18
+    image: *golang_image
     commands: go test ./...
   build:
-    image: golang:1.18
+    image: *golang_image
     commands: build

Example of YAML override and extension

variables: 
  &some-plugin-settings
      settings:
        target: dist
        recursive: false
        try: true

pipelines:
  develop:
    name: Build and test
    image: some-plugin
    settings: *some-plugin-settings
    when:
      branch: develop

  main
    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