如何用 Azure Cli 任务替换 AZ 文件复制任务

时间:2021-03-11 09:35:12

标签: azure-devops yaml

我的 Yaml 管道中有一项任务要上传 Blob 存储中的工件。我能够使用 AZ 文件复制任务(如下所示)为 Windows 代理执行此操作,但对于 Linux 和 Mac 代理却失败了。有人建议我 here 使用 Azure CLI 任务来使其与 Linux 和 Mac 代理一起使用。下面是我编写的 Azure Cli 任务,但它没有说错误为 "[error]Script failed with error: Error: Unable to locate executable file: 'powershell'。请验证文件路径是否存在或文件可以在 PATH 环境变量指定的目录中找到。同时检查文件模式以验证文件是否可执行。 “

我需要一些帮助,以适当的方式构建与我的 Azure 文件复制任务相对应的 Azure Cli 任务。这是两个任务。请建议我做错了什么?

- task: AzureFileCopy@2
          displayName: 'Publish to Blob'
          inputs:
            SourcePath: '$(Build.SourcesDirectory)/ABC-$(osSuffix)'
            azureSubscription: 'Azure CICD'
            Destination: AzureBlob
            storage: '$(BlobStorageAccount)'
            ContainerName: '$(BlobContainer)'
            BlobPrefix: '$(BlobPrefix)/ABC/$(DeploymentVersion)/ABC-$(osSuffix)'
            AdditionalArgumentsForBlobCopy: '/V /S'
            outputStorageUri: BlobUri
            outputStorageContainerSasToken: BlobSASToken



task: AzureCLI@2
          displayName: PublishToBlob
          inputs:
            azureSubscription: 'Azure CICD'
            scriptType: 'ps'
            scriptLocation: 'inlineScript'
            inlineScript: 'az storage blob upload -f '$(Build.SourcesDirectory)/ABC-$(osSuffix)' -c '$(BlobContainer)' -n '$(BlobPrefix)/ABC/$(DeploymentVersion)/ABC-$(osSuffix)'' 


      

1 个答案:

答案 0 :(得分:1)

终于想通了: 给你:

- task: AzureCLI@2
          displayName: PublishToBlob
          inputs:
            azureSubscription: 'Azure CICD'
            scriptType: 'pscore'
            scriptLocation: 'inlineScript'
            inlineScript: az storage blob upload-batch -d "$(BlobContainer)/ABC/$(DeploymentVersion)/ABC-$(osSuffix)" --account-name "mystorageaccount" -s "$(Build.SourcesDirectory)/ABC-$(osSuffix)"
    
相关问题