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

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?

To copy files to Azure with AzCpoy you can use build-in task Azure File Copy, you not need use PowerShell:
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.

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.

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

Related

Cant find extension installed in azure web apps

I have configured an azure web app for PHP with windows OS. I have installed "composer" (for PHP) extension through azure portal and I can see the extension installed.
I can access the batch file when I traverse to the path as well but when I search "where composer" from global paths, then it cant be found. What am I missing? Do I need to add this to env paths somewhere?
What am I missing? Do I need to add this to env paths somewhere?
No, env path is required. To test this i have created a webapp (PHP 7.4, running on windows OS) and ran the below WHERE cmdlet in the below format and able to find the installed extension.
WHERE /R c:\home\SiteExtensions *.bat or WHERE /R c:\home\SiteExtensions composer*
Here is the sample output screenshot for reference:

How to run webtests from a TFS build using powershell script

I have a requirement to run webtests which are located in a particular folder through a build. Currently the tests are run from Visual Studio 2015.
Got to know to execute/use the below powershell script as a task. But clueless how to implement it. Is this powershell script enough?.
param
(
$tool = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe",
$path ,
$include = "*.webtest"
)
$web_tests = get-ChildItem -Path $paths -Recurse -Include $include
foreach ($item in $web_tests) {
$args += "/TestContainer:$item"
}
In this, how to pass in the $path value? Do I need to give the path of the directory which has all these 5 webtests?
Do I need a testsettings file to carry out this execution.
If I need a test settings file, do I need to copy all the webtests file to output directory?
All I get with this powershell is the below message
No test runs are available for this build. Enable automated tests in
your build definition by adding a task that runs tests for your test
framework of choice, such as the Visual Studio Test task. If you choose
to run tests using a custom task or runner, you can publish results
using the Publish Test Results task
Could any one please help me as in what I am missing here? Thanks for your time and help on this.
how to pass in the $path value?
When you use the powershell task to execute your powershell scripts, there is a option Arguments, which you could pass the value of $path:
Do I need to give the path of the directory which has all these 5
webtests?
Yes. In general, the .webtests file are all copied to the drops location, so the path always point to the drops location.
Do I need a testsettings file to carry out this execution.
The short answer is yes.
There is a great blog about how to Running WebTests as part of a VSTS VNext Release pipeline, you can check if it helps.
Hope this helps.

How to download SAS(Shared Acess signature) of an Azure File share onto Linux machine

I have a SAS generated for a file share(with read and list privileges(no write privileges).
my SAS looks like the following format :
“https://test.file.core.windows.net/testf1?[some_token_here]
. I used Azcopy to download the files through above SAS onto a windows virtual machine however Azcopy is not present in Linux.
How do I download the files using the above SAS onto my linux virtual machine(I run ubuntu 14.04 but i prefer a answer that runs on most linux distros)? I'd prefer using a single line of code to carry out the above task. I tried working with Azure-cli but I was unable to find any success.
ps: I am very new to Azure
If you are using the latest Azure-Cli, you might want to try:
azure storage file upload [options] [source] [share] [path]
azure storage file download [options] [share] [path] [destination]
Please try azure storage file for more help information.

How to download a file from ubuntu virtual machine using Azure powershell script

I have created an Ubuntu VM on Azure and I want to download a file stored in one of the directories of this VM.
I want to do this using Powershell.
If you just want to grab a couple files, then you can use pscp. You can download pscp from here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Usage:
pscp.exe -r -pw 'password' 'local-path' adminuser#hostname.cloudapp.net:/path
If you want to do this more than once from multiple clients you can just serve the files with a web server, e.g. Apache. Then you can just use Invoke-WebRequest to download the files via HTTP.
Virtual machines in azure are completely locked down.
Do you just need to download the file once?
I am trying to understand your requirement of using PowerShell.
Here are a few options:
1. manually ftp the file from ubuntu to a FTP server and download it from there.
2. second option for you is to use Azure command line tools that run on ubuntu.
you should install Azure CLI
https://github.com/Azure/azure-xplat-cli
There are instructions for Ubuntu distributions.
One Azure CLI has been isntalled you can use the azure storage command line options to tranfer the file to an azure storage container.
After the files in an azure container you can use PowerShell to download it.
You can also use Azcopy tool to down the file from the container.
https://azure.microsoft.com/en-us/documentation/articles/storage-use-azcopy/
Let me know if this meets your needs.

Microsoft.WindowsAzure.targets "The specified path, file name,or both are too long"

I am trying to publish a project to Windows Azure but get an error in the generated Microsoft.WindowsAzure.targets file related to length of paths and file names. How can I determine which is the problematic path or filename. The error relates to the "" tag in the generated file
Thanks
Martin
Already an older post - did you check this post?
Path too long error when building a windows azure service
This might reslove your issue.
Since this was still a problem for me years later and the above doesn't apply to Azure SDK v2.8, I was able to solve it by creating a symbolic link to my projects folder. Open up the command prompt as an administrator and run this:
mklink /D C:\Dev C:\Users\danzo\Source\Workspaces
Obviously you can change "C:\Dev" to whatever you want it to be and you'll need to change the longer path above to the root directory of your soltions/projects folder.

Resources