Reputation: 731
How can I consume variables set in CI pipeline directly in CD pipeline?
Example: If there are multiply variables declared in one group. How to access particular variable in CI/CD pipeline?
Also how to use variable groups for multiple keyvault's?
Thank you
Upvotes: 2
Views: 2228
Reputation: 4556
Based on Richard's answer, I managed to set the value of a variable in a variable group to a variable coming from a CI pipeline, and then to read that variable in a CD pipeline.
For that, it is necessary:
$(variableName)
. Let's assume its value would be stored in $(variableValue)
).$(variableGroupId)
), which can be done by navigating on Azure DevOps to that variable group. The group ID will then be in the URL.$(personalAccessToken)
)CI pipeline
- powershell: |
az pipelines variable-group variable update --group-id $(variableGroupId) --name $(variableName) --value $(variableValue)
displayName: 'Store the variable in a group variable'
env:
AZURE_DEVOPS_EXT_PAT: $(personalAccessToken)
Then all that's necessary, is to declare the variable group in the CD pipeline. If this variable group is called MyVariableGroup
, it can be done in the following way:
CD pipeline
variables:
- group: MyVariableGroup
The variable that was previously set in the CI pipeline, will then be available in the CD pipeline.
Upvotes: 0
Reputation: 84
Setting up global variables
YAML
CLASSIC
Using Variables
YAML
CLASSIC
Examples:
Batch script: %VARIABLE_NAME%
PowerShell script: $env:VARIABLE_NAME
Bash script: $VARIABLE_NAME
Key Vault
Upvotes: 2