From 1c5e27ea7314b0cc80a1fe19d1f45c7dd798766a Mon Sep 17 00:00:00 2001 From: Shivangi Date: Mon, 11 May 2020 16:32:16 +0530 Subject: [PATCH] Resolving comments --- Tasks/AzureFileCopyV4/AzureFileCopy.ps1 | 4 +++- Tasks/AzureFileCopyV4/AzureFileCopyRemoteJob.ps1 | 15 +++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Tasks/AzureFileCopyV4/AzureFileCopy.ps1 b/Tasks/AzureFileCopyV4/AzureFileCopy.ps1 index a8b43fd7f173..b54568462111 100644 --- a/Tasks/AzureFileCopyV4/AzureFileCopy.ps1 +++ b/Tasks/AzureFileCopyV4/AzureFileCopy.ps1 @@ -118,6 +118,7 @@ try { if([string]::IsNullOrEmpty($containerName) -or ($destination -ne "AzureBlob")) { $containerName = [guid]::NewGuid().ToString() + Write-Verbose "Creating temporary container for uploading files if no input is provided for container name" Create-AzureContainer -containerName $containerName -storageContext $storageContext -isPremiumStorage $isPremiumStorage } else @@ -126,8 +127,9 @@ try { $containerPresent = Get-AzureContainer -containerName $containerName -storageContext $storageContext #creating container if the containerName provided does not exist - if([string]::IsNullOrEmpty($containerPresent) ) + if($containerPresent -eq $null) { + Write-Verbose "Creating container if the containerName provided does not exist" Create-AzureContainer -containerName $containerName -storageContext $storageContext -isPremiumStorage $isPremiumStorage } } diff --git a/Tasks/AzureFileCopyV4/AzureFileCopyRemoteJob.ps1 b/Tasks/AzureFileCopyV4/AzureFileCopyRemoteJob.ps1 index 5d6c411ac7e3..db021c669de0 100644 --- a/Tasks/AzureFileCopyV4/AzureFileCopyRemoteJob.ps1 +++ b/Tasks/AzureFileCopyV4/AzureFileCopyRemoteJob.ps1 @@ -55,13 +55,13 @@ $AzureFileCopyRemoteJob = { $shouldDownload = $true } - $azCopyFolderName = "ADO_AzCopyV10" - $azCopyFolderPath = Join-Path -Path $env:systemdrive -ChildPath $azCopyFolderName - if($shouldDownload) { try { + $azCopyFolderName = "ADO_AzCopyV10" + $azCopyFolderPath = Join-Path -Path $env:systemdrive -ChildPath $azCopyFolderName + New-Item -ItemType Directory -Force -Path $azCopyFolderPath $azCopyZipPath = Join-Path -Path $azCopyFolderPath -ChildPath "AzCopy.zip" @@ -74,7 +74,11 @@ $AzureFileCopyRemoteJob = { $azCopyFolderEnvPath = Join-Path -Path $azCopyFolderPath -ChildPath "AzCopy" + #setting path at machine level so that when user again do copy on VM, there is no need to download the azcopy.exe again [Environment]::SetEnvironmentVariable("Path", $azCopyFolderEnvPath + ';' + $env:Path, [System.EnvironmentVariableTarget]::Machine) + + #setting $env:Path to include azcopy.exe path as the above command used to set path at machine level takes some time to update the path environment variable + $env:Path = $azCopyFolderEnvPath + ';' + $env:Path } catch { @@ -93,10 +97,9 @@ $AzureFileCopyRemoteJob = { $additionalArguments = "--recursive --log-level=INFO" } - $azCopyExeLocation = Join-Path -Path $azCopyFolderPath -ChildPath "AzCopy\AzCopy.exe" - Write-DetailLogs "##[command] & `"$azCopyExeLocation`" copy `"$containerURL*****`" `"$targetPath`" $additionalArguments" + Write-DetailLogs "##[command] & azcopy copy `"$containerURL*****`" `"$targetPath`" $additionalArguments" - $azCopyCommand = "& `"$azCopyExeLocation`" copy `"$containerURL/*$containerSasToken`" `"$targetPath`" $additionalArguments" + $azCopyCommand = "& azcopy copy `"$containerURL/*$containerSasToken`" `"$targetPath`" $additionalArguments" Invoke-Expression $azCopyCommand } catch