functions/Publish-CodeOpsResultsToBlobStorage.ps1
function Publish-CodeOpsResultsToBlobStorage { [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [AllowEmptyString()] [string] $StorageAccountName, [Parameter(Mandatory=$true)] [AllowEmptyString()] [string] $ContainerName, [Parameter(Mandatory=$true)] [AllowEmptyString()] [string] $BlobPath, [Parameter(Mandatory=$true)] [AllowNull()] [securestring] $SasToken, [Parameter(Mandatory=$true)] [string] $JsonFilePath, [Parameter()] [switch] $WhatIf ) # validate the JSON in the source file $jsonData = Get-Content -Raw $JsonFilePath | ConvertFrom-Json -Depth 100 if ($StorageAccountName -and $SasToken -and $ContainerName -and $BlobPath) { $timestamp = $runMetadata.start_time.ToString('yyyyMMddHHmmssfff') # name the file differently for real runs and dry runs $filename = $WhatIf ? "dryrun-$timestamp.json" : "run-$timestamp.json" Write-Information @" Publishing storage account: Source File: $JsonFilePath Account: $StorageAccountName Blob Path: "$ContainerName/$BlobPath/$filename" "@ $uri = "https://{0}.blob.core.windows.net/{1}/{2}/{3}?{4}" -f $StorageAccountName, $ContainerName, $BlobPath, $filename, $SasToken $headers = @{ "x-ms-date" = [System.DateTime]::UtcNow.ToString("R") "x-ms-blob-type" = "BlockBlob" } Invoke-RestMethod -Headers $headers ` -Uri $uri ` -Method PUT ` -Body ($jsonData | ConvertTo-Json -Depth 100 -Compress) ` -Verbose:$false | Out-Null } else { Write-Information "Publishing skipped, due to absent configuration" } } |