Flow enables defining and utilizing environment variables within the pipeline YAML, allowing for the definition of pipeline-level environment variables using variables, and also facilitating the connection to shared variable groups via variableGroups.
Example
variableGroups: [<your-variable-groupid1>,<your-variable-groupid2>] # pipeline-level variable groups
variables: # pipeline-level variables
- key: appname
value: myapp # The default type is String.
- key: envname
type: String # Explicitly specify the type as String.
value: DEV
- key: cloneDepth
type: Number # Explicitly specify the type as Number.
value: 1
- key: isGray
type: Boolean # Explicitly specify the type as Boolean.
value: true
- key: appnames
type: Object # Explicitly specify the type as Object.
value: ["app1","app2","app3"]
- key: releaseItems
type: Object # Explicitly specify the type as Object.
value: {"app1": { "codeUrl": "http://codeurl1.xxx", "repoUrl": "http://repourl1.xxx"}, "app2": { "codeUrl": "http://codeurl2.xxx", "repoUrl": "http://repourl2.xxx"}}
stages:
my_stage:
name: Build Stage
jobs:
my_job:
name: Build Job
steps:
my_step:
name: Command
step: Command
with:
run: |
echo ${appname} # export myapp
echo ${appnames} # export ["app1", "app2", "appm"]Variable priority
Pipeline environment variables support runtime settings and static configurations, with their priority adhering to two principles:
Runtime inputs (manual run configuration pop-ups, OpenAPI trigger parameters, Webhook trigger parameters) > Static configurations
Static configuration proximity principle: step > pipeline (variables/variableGroups) > UI configurations (variables/variable groups)
Priority Level | Variable Timing | Variable Configuration Method | Description |
1 | Runtime Input | manual run configurations, OpenAPI triggers, Webhook triggers, etc. at runtime | Do not support secret variables. |
2 | YAML step | Parameters for certain step. | Do not support secret variables; refer "steps" for details. |
3 | YAML pipeline | Variables in YAML. | Do not support secret variables. |
4 | YAML pipeline | Variable groups in YAML. | Support secret variables. When multiple common variable groups contain variables with the same key, the later ones in the association order overlay and take effect. |
5 | UI Configuration | Variables configured on the pipeline's Variables and Caches UI page | Support secret variables. |
6 | UI Configuration | Variable groups configured on the pipeline's Variables and Caches UI page | Support secret variables. When multiple common variable groups contain variables with the same key, the later ones in the association order overlay and take effect. |
It is advisable, in principle, to configure all environment variables within the pipeline YAML. However, two exceptions apply: for confidential settings and runtime configurations/variable selections, it is recommended to utilize UI-based variable configurations or link to common variable groups.
Detailed description
variables
Pipeline level environment variables, support configuration of multiple variables. Variables can be referenced by ${key} in a stage, a job, or a step. In template mode pipeline, {{ .key }} can be used to reference, and as the rendering parameters of the template. Refer to the "template syntax" for details.
variables[].key
Required. Environment variable key, supports 1-128 characters of uppercase and lowercase English letters, numbers, and underscores _ , starting with a letter, case-sensitive (and cannot be repeated with system environment variables).
variables[].type
Optional. Environment variable type. Supported types: String, Number, Boolean, Object.
variables[].value
Required. Environment variable default value.
variableGroups
Supports associating with multiple common variable groups. When multiple common variable groups contain variables with the same key, the later ones in the association order overlay and take effect.