Amruta
Amruta

Reputation: 731

How to consume variables from CI pipeline into CD pipeline directly

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

Upvotes: 2

Views: 2228

Answers (2)

ccoutinho
ccoutinho

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:

  • 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.

Upvotes: 0

Related Questions