【发布时间】:2023-01-05 11:21:03
【问题描述】:
我按照here 的回答创建了一个管道,我的要求是用我在管道中的输入覆盖每个资源的所有当前标签。因此,我决定将 az 命令与“替换”操作一起使用,这样标签将始终被我们提供的任何输入值替换,这将帮助我始终从该管道中确认哪些标签应用于每个资源。
但是正如下面的 yaml 中所给出的,“foreach”is 循环并不像我预期的那样为我工作。下面是顾虑
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 }}'
-
由于我在 az 命令中使用了“替换”操作,它总是替换为 tagList 中的最后一个值,因为所有以前的值都被这个最后一个值替换了。
-
当我向标签值添加一些空格时,这会创建意外的标签。如何在这些标签值中使用空格
-
上面的每个任务都为每个标签创建了多个任务,我将有许多资源作为输入,每个资源超过 10 个标签,因此这将导致非常大的管道并且难以管理。那么我们是否可以更好地整合每个任务中的步骤。
-
在应用标记之前验证或验证标记结果的任何方法。
【问题讨论】:
-
您的用法不正确,请参阅我的答案。 :)
标签: azure-devops azure-pipelines azure-resource-manager azure-cli azure-pipelines-yaml