azure-pipelines-tasks: [REGRESSION]: AzureFileCopyV6 uses wrong path for azcopy.exe

New issue checklist

Task name

AzureFileCopy

Breaking task version

6

Last working task version

5

Regression Description

Builds consuming AzureFileCopy@6 fail with:

FAILING OUTPUT

& azcopy copy "C:\__w\1\s\_out\*"

The term ‘azcopy’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

PASSING OUTPUT

& "AzCopy\AzCopy.exe" copy "C:\__w\1\s\_out\*"

Notice the different path to AzCopy.exe.

I have pinpointed where in the task this change was made. This diff is the reason AzCopy is not found. The utility code is now ignoring the $azCopyExeLocation variable.

diff --git a/Utility.ps1 b/Utility.ps1
index 94beb25e9f..0d8272dd3d 100644
--- a/Utility.ps1
+++ b/Utility.ps1
@@ -242,23 +231,22 @@ function Upload-FilesToAzureContainer
         if ($useSanitizerActivate) {
             # Splitting arguments on space, but not on space inside quotes
             $sanitizedArguments = [regex]::Split($additionalArguments, ' (?=(?:[^"]|"[^"]*")*$)')
             Write-Output "##[command] & azcopy copy `"$sourcePath`" `"$containerURL`" $sanitizedArguments"
-            & azcopy copy $sourcePath $containerURL$containerSasToken $sanitizedArguments
+            & azcopy copy $sourcePath $containerURL $sanitizedArguments
         } else {
-            Write-Output "##[command] & `"$azCopyExeLocation`" copy `"$sourcePath`" `"$containerURL`"  $additionalArguments"
-            $uploadToBlobCommand = "& `"$azCopyExeLocation`" copy `"$sourcePath`" `"$containerURL`" $additionalArguments"
-            Invoke-Expression $uploadToBlobCommand
+            Write-Output "##[command] & azcopy copy `"$sourcePath`" `"$containerURL`" $additionalArguments"
+            $azCopyCommand = "azcopy copy `"$sourcePath`" `"$containerURL`"  $additionalArguments"
+            Invoke-Expression -Command $azCopyCommand
         }

image

Regressed in #19650

This change was made in every instance where azcopy is invoked. /cc @v-mohithgc

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

Windows

Relevant log output

Log output included above.

Full task logs with system.debug enabled

Log output included above.

Repro steps

No response

About this issue

  • Original URL
  • State: open
  • Created 3 months ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

We are also still receiving this error on a self-hosted Windows 2019 Server based image. Any ideas on how to resolve? We are using a WIF for our Azure DevOps Service connection for this task. This was part of why we upgraded to version 6.

PowerShell Version: 5.1.14393.5582 AzFileCopy Version: 6.238.9

`Starting: AzureFileCopy
==============================================================================
Task         : Azure file copy
Description  : Copy files to Azure Blob Storage or virtual machines
Version      : 6.238.9
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-file-copy
==============================================================================
Added TLS 1.2 in session.
Import-Module -Name C:\Users\AzDevOps\Documents\WindowsPowerShell\Modules\Az.Accounts\2.17.0\Az.Accounts.psd1 -Global
Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
Clear-AzContext -Scope Process
Connect-AzAccount System.Collections.Hashtable

Set-AzContext System.Collections.Hashtable
Import-Module -Name C:\Users\AzDevOps\Documents\WindowsPowerShell\Modules\Az.Resources\6.16.1\Az.Resources.psd1 -Global
Import-Module -Name C:\Users\AzDevOps\Documents\WindowsPowerShell\Modules\Az.Storage\6.1.3\Az.Storage.psd1 -Global
Import-Module -Name C:\Users\AzDevOps\Documents\WindowsPowerShell\Modules\Az.Compute\7.2.0\Az.Compute.psd1 -Global
Import-Module -Name C:\Users\AzDevOps\Documents\WindowsPowerShell\Modules\Az.Network\7.4.1\Az.Network.psd1 -Global
##[warning]The names of some imported commands from the module 'Microsoft.Azure.PowerShell.Cmdlets.Network' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
##[warning]The names of some imported commands from the module 'Az.Network' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
 mime: C:\a\_tasks\AzureFileCopy_eb72cb01-a7e5-427b-a8a1-1b31ccac8a43\6.238.9\MimeMapping.json
Account                              SubscriptionName TenantId                             Environment
-------                              ---------------- --------                             -----------
REDACTED AZURE TENANT/SUBSCRIPTION

Uploading files from source path: 'C:\a\1\s\*.exe' to storage account: 'REDACTED' in container: 'REDACTED' with blob prefix: 'REDACTED-2-buildPipeline-20240423.7'
 & "AzCopy\AzCopy.exe" copy "C:\a\1\s\*.exe" "[REDACTED"](REDACTED)  --log-level=INFO --recursive
INFO: Scanning...

Failed to perform Auto-login: PSContextCredentialexec: "pwsh": executable file not found in %PATH%.`

Yes, judging by the contents of the task’s make.json:

    "externals": {
        "archivePackages": [
            {
                "url": "https://vstsagenttools.blob.core.windows.net/tools/azcopy/10.12/AzCopy.zip",
                "dest": "./"
            }
        ],
// ...

… and the contents of that archive …

$ tar tf .\AzCopy.zip
AzCopy/AzCopy.exe

the path to azcopy.exe must contain AzCopy/, otherwise the task is actually taking a dependency on the azcopy.exe available in the environment. This means that the task, instead of using AzCopy 10.12 which it ships with, will use whatever AzCopy is on the machine already. That can result in significant regressions if the agent contains an older AzCopy.

Still getting same error:

failed with error: ‘The term ‘azcopy’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.’ For more info please refer to https://aka.ms/azurefilecopyreadme

@v-mohithgc @DHowett

Hi @DevTestUser123, the changes have been merged today and it will take 5-7 working days to be deployed on all the regions. The new version of the task (ie 6.238.0) will contain the fix.