Storage/Copy-FileToAzureStorage.ps1
<#
.Synopsis Function for publishing build output from Run-AlPipeline to storage account .Description Modified version of Freddy's https://github.com/microsoft/navcontainerhelper/blob/master/PackageHandling/Publish-BuildOutputToStorage.ps1 .Parameter StorageConnectionString A connectionstring with access to the storage account in which you want to publish artifacts (SecureString or String) .Parameter containerName Project name of the app you want to publish. This becomes part of the blob url. .Parameter destinationPath Path inside blob of the archive you want to publish. This becomes part of the blob url. .Parameter permission Specifies the public level access to the container (if it gets created by this function) Default is Container, which provides full access. Other values are Blob or Off. .Parameter filename Path containing the file to be published. #> function Copy-FileToAzureStorage { Param( [Parameter(Mandatory=$true)] $StorageConnectionString, [Parameter(Mandatory=$true)] [string] $containerName, [Parameter(Mandatory=$false)] [ValidateSet('Container','Blob','Off')] [string] $permission = "Blob", [Parameter(Mandatory=$true)] $filename, [Parameter(Mandatory=$true)] [string] $destinationPath ) if ($StorageConnectionString -is [SecureString]) { $StorageConnectionString = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($StorageConnectionString)) } if ($StorageConnectionString -isnot [string]) { throw "StorageConnectionString needs to be a SecureString or a String" } $containerName = $containerName.ToLowerInvariant() Write-Host "Publishing to Storage:" Write-Host " - Container Name: " $containerName Write-Host " - Blob Name: " $destinationPath if (!(get-command New-AzureStorageContext -ErrorAction SilentlyContinue)) { Set-Alias -Name New-AzureStorageContext -Value New-AzStorageContext Set-Alias -Name New-AzureStorageContainer -Value New-AzStorageContainer Set-Alias -Name Set-AzureStorageBlobContent -Value Set-AzStorageBlobContent } $storageContext = New-AzureStorageContext -ConnectionString $StorageConnectionString New-AzureStorageContainer -Name $containerName -Context $storageContext -Permission $permission -ErrorAction Ignore | Out-Null Write-Host "Saving..." Set-AzureStorageBlobContent -File $filename -Context $storageContext -Container $containerName -Blob $destinationPath -Force | Out-Null Write-Host "Saved $destinationPath to $containerName" } Write-Verbose "Function imported: Copy-AppsToAzureStorage" |