2

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?

enter image description here

Also how to use variable groups for multiple keyvault's?

Thank you

riQQ
  • 9,878
  • 7
  • 49
  • 66
Amruta
  • 701
  • 4
  • 15
  • 38
  • Possible duplicate of [How to get the variable value in TFS/AzureDevOps from Build to Release Pipeline?](https://stackoverflow.com/questions/52568195/how-to-get-the-variable-value-in-tfs-azuredevops-from-build-to-release-pipeline) – Shayki Abramczyk Jun 03 '19 at 11:13

2 Answers2

0

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:

  • To have previously created the variable group, and the variable (its name identified by $(variableName). Let's assume its value would be stored in $(variableValue)).
  • To find the variable group ID (stored in $(variableGroupId)), which can be done by navigating on Azure DevOps to that variable group. The group ID will then be in the URL.
  • A Personal Access Token (PAT) with Read & Write access to group variables (called $(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.

ccoutinho
  • 3,308
  • 5
  • 39
  • 47