Skip to content

Commit

Permalink
Backward compatibility when setting pipeline variables from managemen…
Browse files Browse the repository at this point in the history
…t group hierarchy (Azure#213)
  • Loading branch information
SenthuranSivananthan authored Mar 12, 2022
1 parent 30b9cc2 commit 97c2904
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions .pipelines/templates/steps/load-variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,39 @@ steps:

# Load Variables
- task: Bash@3
displayName: Load Variables
condition: ne(variables['var-managementgroup-hierarchy'], '')
displayName: Load variables from Management Group hierarchy
inputs:
targetType: inline
script: |
$(var-bashPreInjectScript)
### -------------------------------------------------------------------------------------------------
### Create the 'var-parentManagementGroupId' and 'var-topLevelManagementGroupName'
### variables (used in YAML pipeilne definitions) based on information extracted from the
### variables (used in YAML pipeline definitions) based on information extracted from the
### newer 'var-managementgroup-hierarchy' variable, if it is defined.
### -------------------------------------------------------------------------------------------------
hierarchyJson='$(var-managementgroup-hierarchy)'
if [[ -n $hierarchyJson ]]; then
echo "The new 'var-managementgroup-hierarchy' variable IS defined."
echo "REMAPPING 'var-parentManagementGroupId' and 'var-topLevelManagementGroupName' variables."
echo "SETTING 'var-parentManagementGroupId' and 'var-topLevelManagementGroupName' variables."
parentManagementGroupId=`echo $hierarchyJson | jq -r '.id'`
topLevelManagementGroupName=`echo $hierarchyJson | jq -r '.children[0].id'`
echo "##vso[task.setvariable variable=var-parentManagementGroupId]$parentManagementGroupId"
echo "##vso[task.setvariable variable=var-topLevelManagementGroupName]$topLevelManagementGroupName"
else
echo "The new 'var-managementgroup-hierarchy' variable IS NOT defined."
echo "USING existing 'var-parentManagementGroupId' and 'var-topLevelManagementGroupName' variables."
echo "var-parentManagementGroupId=$parentManagementGroupId"
echo "var-topLevelManagementGroupName=$topLevelManagementGroupName"
fi
### -------------------------------------------------------------------------------------------------
### Add more scripts here to remap other variables. For example, if you refactor for existing (flat)
### variables to represent them in JSON notation (objects), then this is a useful approach to
### maintaining backward compatibility while supporting a newer and improved configuration schema.
### Add more scripts here to remap other variables using management group hierarchy. For example,
### if you refactor for existing (flat) variables to represent them in JSON notation (objects), then
### this is a useful approach to maintaining backward compatibility while supporting a newer and improved
### configuration schema.
### -------------------------------------------------------------------------------------------------
$(var-bashPostInjectScript)

0 comments on commit 97c2904

Please sign in to comment.