如何解决Azure 管道 foreach 循环
我在找出此管道中的问题时遇到了一些问题。
我有一个 GitHub 存储库,其中包含一个名为 dist
的文件夹。这个文件夹里面有多个文件和文件夹。这是我的 git hub 的结构:
├── README.md
├── client_pipeline.yaml
├── client_template.yaml
└── dist
├── ReportPhishingOutlookAddIn.xml
└── ReportPhishingOutlookAddInWeb
├── Content
├── Dialog.html
├── Functions
├── Images
└── Scripts
我想要做的是,当我在这个 repo 中创建一个新文件夹时,我的管道应该触发并将 dist 文件夹内容上传到这个新文件夹中,并将其保存在 azure 存储中。
所以我决定先用一个天蓝色的管道模板来定义管道的逻辑:
Client_template.yaml
parameters:
storageaccount: ''
client: []
steps:
- ${{ each client in parameters.client }}:
- task: AzureCLI@2
displayName: 'Azure CLI'
inputs:
AzureSubscription: '<mysubscription>'
scriptType: bash
scriptLocation: inlinescript
inlinescript: |
az storage blob upload-batch --source dist --destination '$web/${client}' --account-name ${{ parameters.storageaccount}} --output table --no-progress
client_pipeline.yaml
variables:
- name: storageaccount
value: <mystorageaccount>
steps:
- template: client_template.yaml
parameters:
storageaccount: ${{ variables.storageaccount }}
client: ["folder","folder1"]
我使用的第二个管道让我可以自由添加任意数量的客户端,并且管道应该只在一个 azure 存储帐户中创建它们。
当我运行我的管道时,它可以毫无问题地构建所有内容,但是当我进入我的存储帐户时,我遇到了 2 个问题。
第一个是文件夹名称是 ${client}
而不是我在数组中指定的名称的实际名称。
有什么帮助吗?
编辑: 我解决了问题 1,现在我可以创建多个文件夹。 但它仍然没有复制 dist 内文件夹中的所有子文件夹和文件
解决方法
引用此线程:https://github.com/Azure/azure-cli/issues/5420#issuecomment-487169413,
"shopName": "jmart","products": [{
"id": 1,"name": "Clean and Clear Deep Clean Cleanser 100g","slug": "8d1c895c-6911-4fc8-a34c-89c6948233d7","price": 4.5,"discount_price": 0,"category": "Health and Beauty","sale": false,"subcategory": "personal care","color": "black","article": "Clean and Clear","quantity": 9,"img": "https://firebasestorage.googleapis.com/v0/b/swifty-products.appspot.com/o/Jmart%2FBeauty%2FClean%20and%20Clear%20Deep%20Clean%20Cleanser%20100g.jpg?alt=media","vendor": {
"id": 1,"name": "Clean and Clear"
},"ratings": {
"star_ratings": 0,"votes": 0
},"isAvailable": true
},{
"id": 2,"name": "Colgate Total Pro Breath Health","slug": "67626dae-1537-40d8-837d-483e5759ada0","article": "Colgate","img": "https://firebasestorage.googleapis.com/v0/b/swifty-products.appspot.com/o/Jmart%2FBeauty%2FColgate%20Total%20Pro%20Breath%20Health.jpg?alt=media","vendor": {
"id": 2,"name": "Colgate"
},]
如果需要上传子文件夹,可以添加标志az storage azcopy blob upload
-c containerName
--account-name accountName
-s directory/path
-d upload/path
。
因此,您可以有一个递归标志,设置后将上传子目录。在 az storage blob upload-batch 中包含 --recursive
标志将上传子目录。一个例子可能是 --recursive
。不包括递归标志将只上传特定目录的文件。
更新>> 由于 Nayden 已通过使用上传批处理解决了此问题。如果子文件夹为空,它会被忽略并且不会被复制。一旦我们将一些文件放入所有子文件夹中,upload-batch 就进行了递归复制,没有任何额外的标志。
在这里发帖,以便其他遇到相同问题的社区成员可以快速找到答案。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。