Skip to content

Commit

Permalink
Users/razvanmanole/az file copy 4and5 blob prefix fix (#18494)
Browse files Browse the repository at this point in the history
* Fix AzFileCopy v4 and V5 BlobPrefix to threat it as a folder in case it ends with /

* Update description for blobPrefix property

* Update also the resources.resjson
  • Loading branch information
manolerazvan authored Jun 15, 2023
1 parent 2b4fb85 commit 3fa5142
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"loc.input.label.StorageAccountRM": "RM Storage Account",
"loc.input.help.StorageAccountRM": "Specify a pre-existing ARM storage account. It is also used as an intermediary for copying files to Azure VMs",
"loc.input.label.ContainerName": "Container Name",
"loc.input.help.ContainerName": "Name of the Container for uploading the files. If a container with the given name does not exist in the specified storage account, it will automatically be created. <br> If you need to create a virtual directory inside the container, use the blob prefix input below. <br> Example: If your target location is <i>https://myaccount.blob.core.windows.net/mycontainer/vd1/vd2/</i>, then specify <i>mycontainer</i> as container name and <i>vd1/vd2</i> as blob prefix.",
"loc.input.help.ContainerName": "Name of the Container for uploading the files. If a container with the given name does not exist in the specified storage account, it will automatically be created. <br> If you need to create a virtual directory inside the container, use the blob prefix input below. <br> Example: If your target location is <i>https://myaccount.blob.core.windows.net/mycontainer/vd1/vd2/</i>, then specify <i>mycontainer</i> as container name and <i>vd1/vd2/</i> as blob prefix.",
"loc.input.label.BlobPrefix": "Blob Prefix",
"loc.input.help.BlobPrefix": "Useful for filtering files, for example, append build number to all the blobs to download files from that build only. Example: If you specify blob prefix as <i>myvd1</i>, a virtual directory with this name will be created inside the container. The source files will be copied to <i>https://myaccount.blob.core.windows.net/mycontainer/myvd1/</i>.",
"loc.input.help.BlobPrefix": "Useful for filtering files, for example, append build number to all the blobs to download files from that build only. Example: If you specify blob prefix as <i>myvd1/</i>, a virtual directory with this name will be created inside the container. Blob prefix with a trailing '/' will be considered a virtual directory. Otherwise, it will be treated as a file, unless the item being copied is itself a folder. The source files will be copied to <i>https://myaccount.blob.core.windows.net/mycontainer/myvd1/</i>.",
"loc.input.label.EnvironmentNameRM": "Resource Group",
"loc.input.help.EnvironmentNameRM": "Name of the target Resource Group for copying files to.",
"loc.input.label.ResourceFilteringMethod": "Select Machines By",
Expand Down
5 changes: 4 additions & 1 deletion Tasks/AzureFileCopyV4/Utility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ function Upload-FilesToAzureContainer
Write-Output (Get-VstsLocString -Key "AFC_UploadFilesStorageAccount" -ArgumentList $sourcePath, $storageAccountName, $containerName, $blobPrefix)

$blobPrefix = $blobPrefix.Trim()
$containerURL = [string]::Format("{0}/{1}/{2}", $blobStorageEndpoint.Trim("/"), $containerName, $blobPrefix).Trim("/")
$trailingChars = [regex]::Escape("/") + '+$'
$blobPrefix = $blobPrefix -replace $trailingChars, "/"
$containerURL = [string]::Format("{0}/{1}/{2}", $blobStorageEndpoint.Trim("/"), $containerName, $blobPrefix.TrimStart("/"))

$containerURL = $containerURL.Replace('$','`$')
$azCopyExeLocation = Join-Path -Path $azCopyLocation -ChildPath "AzCopy.exe"

Expand Down
4 changes: 2 additions & 2 deletions Tasks/AzureFileCopyV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"label": "Container Name",
"defaultValue": "",
"required": true,
"helpMarkDown": "Name of the Container for uploading the files. If a container with the given name does not exist in the specified storage account, it will automatically be created. <br> If you need to create a virtual directory inside the container, use the blob prefix input below. <br> Example: If your target location is <i>https://myaccount.blob.core.windows.net/mycontainer/vd1/vd2/</i>, then specify <i>mycontainer</i> as container name and <i>vd1/vd2</i> as blob prefix.",
"helpMarkDown": "Name of the Container for uploading the files. If a container with the given name does not exist in the specified storage account, it will automatically be created. <br> If you need to create a virtual directory inside the container, use the blob prefix input below. <br> Example: If your target location is <i>https://myaccount.blob.core.windows.net/mycontainer/vd1/vd2/</i>, then specify <i>mycontainer</i> as container name and <i>vd1/vd2/</i> as blob prefix.",
"visibleRule": "Destination = AzureBlob"
},
{
Expand All @@ -82,7 +82,7 @@
"label": "Blob Prefix",
"defaultValue": "",
"required": false,
"helpMarkDown": "Useful for filtering files, for example, append build number to all the blobs to download files from that build only. Example: If you specify blob prefix as <i>myvd1</i>, a virtual directory with this name will be created inside the container. The source files will be copied to <i>https://myaccount.blob.core.windows.net/mycontainer/myvd1/</i>.",
"helpMarkDown": "Useful for filtering files, for example, append build number to all the blobs to download files from that build only. Example: If you specify blob prefix as <i>myvd1/</i>, a virtual directory with this name will be created inside the container. Blob prefix with a trailing '/' will be considered a virtual directory. Otherwise, it will be treated as a file, unless the item being copied is itself a folder. The source files will be copied to <i>https://myaccount.blob.core.windows.net/mycontainer/myvd1/</i>.",
"visibleRule": "Destination = AzureBlob"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"loc.input.label.StorageAccountRM": "RM Storage Account",
"loc.input.help.StorageAccountRM": "Specify a pre-existing ARM storage account. It is also used as an intermediary for copying files to Azure VMs",
"loc.input.label.ContainerName": "Container Name",
"loc.input.help.ContainerName": "Name of the Container for uploading the files. If a container with the given name does not exist in the specified storage account, it will automatically be created. <br> If you need to create a virtual directory inside the container, use the blob prefix input below. <br> Example: If your target location is <i>https://myaccount.blob.core.windows.net/mycontainer/vd1/vd2/</i>, then specify <i>mycontainer</i> as container name and <i>vd1/vd2</i> as blob prefix.",
"loc.input.help.ContainerName": "Name of the Container for uploading the files. If a container with the given name does not exist in the specified storage account, it will automatically be created. <br> If you need to create a virtual directory inside the container, use the blob prefix input below. <br> Example: If your target location is <i>https://myaccount.blob.core.windows.net/mycontainer/vd1/vd2/</i>, then specify <i>mycontainer</i> as container name and <i>vd1/vd2/</i> as blob prefix.",
"loc.input.label.BlobPrefix": "Blob Prefix",
"loc.input.help.BlobPrefix": "Useful for filtering files, for example, append build number to all the blobs to download files from that build only. Example: If you specify blob prefix as <i>myvd1</i>, a virtual directory with this name will be created inside the container. The source files will be copied to <i>https://myaccount.blob.core.windows.net/mycontainer/myvd1/</i>.",
"loc.input.help.BlobPrefix": "Useful for filtering files, for example, append build number to all the blobs to download files from that build only. Example: If you specify blob prefix as <i>myvd1/</i>, a virtual directory with this name will be created inside the container. Blob prefix with a trailing '/' will be considered a virtual directory. Otherwise, it will be treated as a file, unless the item being copied is itself a folder. The source files will be copied to <i>https://myaccount.blob.core.windows.net/mycontainer/myvd1/</i>.",
"loc.input.label.EnvironmentNameRM": "Resource Group",
"loc.input.help.EnvironmentNameRM": "Name of the target Resource Group for copying files to.",
"loc.input.label.ResourceFilteringMethod": "Select Machines By",
Expand Down
5 changes: 4 additions & 1 deletion Tasks/AzureFileCopyV5/Utility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ function Upload-FilesToAzureContainer
Write-Output (Get-VstsLocString -Key "AFC_UploadFilesStorageAccount" -ArgumentList $sourcePath, $storageAccountName, $containerName, $blobPrefix)

$blobPrefix = $blobPrefix.Trim()
$containerURL = [string]::Format("{0}/{1}/{2}", $blobStorageEndpoint.Trim("/"), $containerName, $blobPrefix).Trim("/")
$trailingChars = [regex]::Escape("/") + '+$'
$blobPrefix = $blobPrefix -replace $trailingChars, "/"
$containerURL = [string]::Format("{0}/{1}/{2}", $blobStorageEndpoint.Trim("/"), $containerName, $blobPrefix.TrimStart("/"))

$containerURL = $containerURL.Replace('$','`$')
$azCopyExeLocation = Join-Path -Path $azCopyLocation -ChildPath "AzCopy.exe"
if($cleanTargetBeforeCopy)
Expand Down
4 changes: 2 additions & 2 deletions Tasks/AzureFileCopyV5/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"label": "Container Name",
"defaultValue": "",
"required": true,
"helpMarkDown": "Name of the Container for uploading the files. If a container with the given name does not exist in the specified storage account, it will automatically be created. <br> If you need to create a virtual directory inside the container, use the blob prefix input below. <br> Example: If your target location is <i>https://myaccount.blob.core.windows.net/mycontainer/vd1/vd2/</i>, then specify <i>mycontainer</i> as container name and <i>vd1/vd2</i> as blob prefix.",
"helpMarkDown": "Name of the Container for uploading the files. If a container with the given name does not exist in the specified storage account, it will automatically be created. <br> If you need to create a virtual directory inside the container, use the blob prefix input below. <br> Example: If your target location is <i>https://myaccount.blob.core.windows.net/mycontainer/vd1/vd2/</i>, then specify <i>mycontainer</i> as container name and <i>vd1/vd2/</i> as blob prefix.",
"visibleRule": "Destination = AzureBlob"
},
{
Expand All @@ -82,7 +82,7 @@
"label": "Blob Prefix",
"defaultValue": "",
"required": false,
"helpMarkDown": "Useful for filtering files, for example, append build number to all the blobs to download files from that build only. Example: If you specify blob prefix as <i>myvd1</i>, a virtual directory with this name will be created inside the container. The source files will be copied to <i>https://myaccount.blob.core.windows.net/mycontainer/myvd1/</i>.",
"helpMarkDown": "Useful for filtering files, for example, append build number to all the blobs to download files from that build only. Example: If you specify blob prefix as <i>myvd1/</i>, a virtual directory with this name will be created inside the container. Blob prefix with a trailing '/' will be considered a virtual directory. Otherwise, it will be treated as a file, unless the item being copied is itself a folder. The source files will be copied to <i>https://myaccount.blob.core.windows.net/mycontainer/myvd1/</i>.",
"visibleRule": "Destination = AzureBlob"
},
{
Expand Down

0 comments on commit 3fa5142

Please sign in to comment.