Make pipeline variables read-only
masterTo prevent steps from accidentally or maliciously overwriting important data, you can mark variables as read-only. Once a variable is marked as read-only, any attempt to change its value using the ##vso[task.setVariable] logging command will generate a warning: VariableName is read-only and can't be changed.
The following types of variables are treated as read-only:
- System variables: All variables prefixed with
System.,Agent.,Build., etc. - Output variables: Variables set with
isOutput=true. - Queue-time variables: Variables provided by the server at queue time.
- Script-created variables: Variables set via logging commands with the
isReadonly=trueproperty. - YAML-defined variables: Variables defined in the YAML pipeline using the
readonly: trueproperty.
variables:
- name: first
value: one
readonly: true # new syntax marking this variable readonly
steps:
- script: echo "##vso[task.setVariable variable=second;isReadonly=true]two"
displayName: Set a readonly variable from a script/task
- script: echo "##vso[task.setVariable variable=third;isOutput=true]three"
displayName: Output variables are automatically readonly
- script: echo Another readonly variable is $(Build.SourcesDirectory)
displayName: System variables are readonly