Variables
Variables can be set at pipeline, stage and step levels.
note
The order of precedence for environment variables with the same name is step > stage > pipeline.
Pipeline
Pipeline environment variables are available to all run steps in your pipeline.
kind: pipeline
spec:
options:
envs:
GOOS: linux
GOARCH: amd64
stages:
- type: ci
spec:
steps:
- name: test 1.20
type: run
spec:
container: golang:1.20
script: |
go build
go test
- name: test 1.21
type: run
spec:
container: golang:1.21
script: |
go build
go test
Stage
Stage environment variables are available to all run steps in the stage.
kind: pipeline
spec:
stages:
- type: ci
spec:
envs:
GOOS: linux
GOARCH: amd64
steps:
- name: test 1.20
type: run
spec:
container: golang:1.20
script: |
go build
go test
- name: test 1.21
type: run
spec:
container: golang:1.21
script: |
go build
go test
Step
Run step environment variables are only available to the step.
kind: pipeline
spec:
stages:
- type: ci
spec:
steps:
- name: test
type: run
spec:
container: golang
envs:
GOOS: linux
GOARCH: amd64
script: |
go build
go test
Background steps also support environment variables.
kind: pipeline
spec:
stages:
- type: ci
spec:
steps:
- name: database
type: background
spec:
container: mariadb
envs:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: test
- name: test
type: run
spec:
container: mariadb
script: |-
sleep 15
mariadb -u root -h database --execute="SELECT VERSION();"