我正在使用Azure DevOps及其构建和发布管道。作为构建的一部分,我想从Azure Blob存储中删除旧文件。我正在使用ubuntu-latest
vmImage。
此任务:
- task: AzureCLI@2
displayName: Delete old files
inputs:
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
date=`date -d "1 days ago" '+%Y-%m-%dT%H:%MZ'`
az storage blob delete-batch -s $web --account-name xenobellstorage --if-unmodified-since $date
产生此错误,该错误与文档中的任何参数都不匹配。
Script failed with error: Error: Input required: connectedServiceNameARM
如果我将azureSubscription: 'Main subscription'
添加到任务中,则会出现此错误,并且出现授权资源按钮不起作用。
There was a resource authorization issue: "The pipeline is not valid. Job Job: Step AzureCLI input connectedServiceNameARM references service connection Main subscription which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz."
linked page建议我进入项目设置以授权所有管道,但是该切换无效。
如何在Ubuntu VM上运行AzureCLI任务?
我用来解决问题的完整YAML文件:
# Node.js
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
displayName: 'npm install'
- script: |
grunt --gruntfile gruntfile.js prod
displayName: 'grunt production build'
- task: CopyFiles@2
displayName: 'Copy files'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)'
Contents: |
game/**
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish files'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
- task: AzureCLI@2
displayName: Delete old files
inputs:
azureSubscription: 'Main subscription (abc-123-idd)'
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
az storage blob delete-batch -s '$web' --account-name mystorage --if-unmodified-since $(date -d "1 days ago" '+%Y-%m-%dT%H:%MZ')
答案 0 :(得分:1)
您需要添加正确的azureSubscription
,如下所示:
steps:
- task: AzureCLI@1
displayName: 'Azure CLI '
inputs:
azureSubscription: 'ARMConnection'
scriptLocation: inlineScript
inlineScript: 'xxx'
并且如the linked page中所述:必须先对资源进行授权,然后才能使用它们,因此,请按照指南尝试对资源进行授权。
首先,请导航至Project setting
并单击Server Connections
,请检查您的端点所使用的连接是否仍然存在,并确保其正常工作,只需确保您可以验证连接是否成功(编辑连接->验证连接)。还请确保服务连接已分配了必要的角色。
答案 1 :(得分:0)
您的azureSubscription
必须与服务连接的实际名称匹配。因此不是Azure订阅名称,而是在Azure Devops中创建的用于管理该订阅的服务连接。
答案 2 :(得分:0)
使用AzureCLI版本2
- task: AzureCLI@2
displayName: "Azure Storage - delete old files"
inputs:
azureSubscription: 'xxxx-PAYG(xxx-xxx-xxx-xxx-xxx)'
scriptType: 'ps'
scriptLocation: 'inlineScript'
inlineScript: 'az storage remove --account-name ''xxx'' --container-name ''$web'' -r'