我在Devops中有此任务:我想将文本文件从Blobstorage复制到VM。
- task: AzureFileCopy@4
inputs:
sourcePath: 'https://storagename.blob.core.windows.net/container/file.txt'
azureSubscription: 'subscription connection'
storage: 'a_storage_in_subscription'
resourceGroup: $(rgName_of_VM)
destination: 'azureVMs'
MachineNames: $(ipofVM)
vmsAdminUserName: $(adminUsername)
vmsAdminPassword: $(adminPassword)
targetPath: 'c:\files'
但是它失败并显示Upload to container: '8e107770-69d8-xxx' in storage account: 'a_storage_in_subscription' with blob prefix: '' failed with error: 'AzCopy.exe exited with non-zero exit code while uploading files to blob storage.' For more info please refer to https://aka.ms/azurefilecopyreadme
我的理解是,该任务将复制文件,然后将其首先放入“存储”字段中的容器中(使用GUID来创建它)。任务成功完成,但随后发生错误。我在做什么错了?
答案 0 :(得分:1)
如果您重新运行此失败的管道,并将system.debug
设置为true
,则会看到另一条消息,其中更详细地解释了失败的原因:failed to perform copy command due to error: cannot start job due to error: cannot scan the path \\?\D:\a\1\s\https://storagename.blob.core.windows.net/container/file.txt
。
现在,您应该知道为什么遇到该错误消息。这是因为我们的Azure File Copy
任务不支持在sourcePath
中使用HTTPS url。 sourcePath
的值必须满足以下条件:
由于我们不支持在此处使用HTTPS网址。解决方法是,首先可以使用Azure cli
命令将此文件download首先构建到构建工作目录中。然后将其上传到AzureVM
:
- task: AzureCLI@1
displayName: 'Azure CLI '
inputs:
azureSubscription: {subscription}
scriptLocation: inlineScript
inlineScript: |
mkdir $(Build.SourcesDirectory)/File
az storage blob download --container-name {container name} --file $(Build.SourcesDirectory)/file --name {file name} --account-key $(accountkey) --account-name {blob name}
- task: AzureFileCopy@4
displayName: 'AzureVMs File Copy'
inputs:
SourcePath: '$(Build.SourcesDirectory)/File'
azureSubscription: {subscription}
Destination: AzureVMs
storage: {storage}
resourceGroup: '{resource group}'
vmsAdminUserName: {login name}
vmsAdminPassword: {login password}
TargetPath: 'xxx'
注意:您可以从此标签中获取accesskey
:
现在,您可以看到可以成功将文件上传到AzureVM。