developer9969
developer9969

Reputation: 5236

AzCopy (devops pipeline)is not recognized as the name of a cmdlet, function, script file, or operable program

I have a PowerShell script that works all the time when I use from my local machine (I have azCopy installed):

AzCopy `
/Source:C:\myfolder `
/Dest:https://mystorageaccount.blob.core.windows.net/mystoragecontainer `
/DestKey:<storage-account-access-key> `
/Pattern:"myfile.txt"

Using azure pipeline (Microsoft Hosted agent) this script fails with

"AzCopy.exe : The term 'AzCopy.exe' is not recognized as the name of a cmdlet, function, script file, or operable program."

I have tried different agents but still the same error. Which agent I must use to use azCopy?

Am I missing the obvious?

Is there another way of doing this always using powershell?

Upvotes: 4

Views: 11268

Answers (3)

Exatex
Exatex

Reputation: 359

For people like me, landing to this thread because they have this error by calling AZ copy in a PS Script, it's confirmed AZ Copy in not installed in Last (VM2019) version of Windows Hosted. But according to MS, binary is present in the Image, so you don't have to install it, but just to use the right path. For more information about packages installed (or saved) on VM, you can check this Git Repo

Upvotes: 0

Mengdi Liang
Mengdi Liang

Reputation: 18978

Agree with Shayki Abramczyk, the Azcopy task he provided can also be used to achieve copy file. This is another way, you can consider give it a try :-)

Back to this issue. According to error message, I think it's because the missing SDK in hosted agent.

Until now, Microsoft does not install Azure.Storage.AzCopy in every hosted agent. So, the agent you used may does not support this.

We provide seven different agents for user use, but only Hosted VS2017, Hosted Windows 2019 with VS2019 and Hosted Ubuntu 1604 has been installed the SDK which support Azcopy.exe.

So, you can try with these three agents to execute your azcopy command with powershell.

Edit:

Becaues the executable file (azcopy.exe)is in local. So, where is your AzCopy.exe located? For me, it's C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy.

So, in script, you need to execute cd command to change directory to the file where AzCopy.exe located first.

cd “C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy”

Note: DO NOT lost double quote here, or you will get x86 is not recognized. If file path located not same with mine, just change file path with yours.

And then, because of using Powershell, you may need to use powershell syntax. Here is the complete format example which modify it based on your script:

$source="C:\MyFolder"
$dest="https://mystorageaccount.blob.core.windows.net/mystoragecontainer"
$pattern = "myfile.txt"
$destkey = <key>

cd “C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy”
$azcopy = .\AzCopy.exe /Source:$source /Dest:$dest /DestKey: $destkey 
/Pattern: $pattern

Please try with it.

Upvotes: 0

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41595

To copy files to Azure with AzCpoy you can use build-in task Azure File Copy, you not need use PowerShell:

enter image description here

In addition, you can install the Microsoft Azure Build and Release Tasks extension that give you another task "Azure Copy File Extended" with more options.

Upvotes: 1

Related Questions