I have created a pipeline by following the answer here and my requirement is to override all the current tags of each resources with my inputs in the pipeline. So I decided to use the az command with "replace" operation so that the tags will be always replaced with whatever input values we are given, and which will help me to always confirm from this pipeline what tags are applied to each resources.
But as given in the below yaml, the "foreach" is loop is not working for me the way which I expected. Below are the concerns
trigger:
- none
pool:
name: mypool
parameters:
- name: myEnvironments
type: object
default:
- development
- name: tagList
type: object
default:
- resourcename: resource1
todeploy: yes
allure_envtest_1: allure_envtest_1_value
allure_envtest_2: allure envtest value
- resourcename: resource 2
todeploy: yes
trip_envtest_1: trip_envtest_1_value
trip_envtest_2: trip_envtest_2_value
stages:
- ${{ each environment in parameters.myEnvironments }}:
- stage:
displayName: 'Create Tag in ${{ environment }}'
pool:
name: mypool
jobs:
- ${{ each tag in parameters.tagList }}:
- ${{ each tagcontent in tag }}:
- ${{ if and(ne(tagcontent.Key, 'resourcename'),ne(tagcontent.Key, 'todeploy')) }}:
- job:
displayName: 'Tag the reource ${{ tag.resourcename }}'
steps:
- task: AzureCLI@2
displayName: "Tag the resource"
inputs:
azureSubscription: ""
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: 'az tag update --resource-id ${{ tag.resourcename }} --operation replace --tags ${{ tagcontent.Key }}=${{ tagcontent.value }}'
Since I used "Replace" operation in az command, its always replacing with the last value from tagList, because all the previous values are replaced with this last value.
When I am adding some spaces to the tag values, which is creating unexpected tags. how to use spaces in these tag values
the above for each tasks are creating multiple tasks for each tags and I will have many resources as input with more than 10 tags each, So which will result very big pipeline and difficult to manage. So whether we can consolidate the steps in each task in better way.
Any ways to verify or validate the results of tagging , before its getting applied.