Resolving DownloadString Error in Azure DevOps Pipelines
On May 1st, we encountered a new error in our Azure DevOps pipelines. The error occurred while using PowerShell scripts to download the bccontainerhelper. This blog post will detail the issue, the investigation process, and the solution to resolve the error.
Issue Description
Our pipelines started throwing a DownloadString error when attempting to download the bccontainerhelper. This error was unexpected and disrupted our workflow. Upon investigation, we discovered that the issue was due to changes in the bccontainerhelper module, specifically starting from version 6.1.
You can see an issue logged in Github related to this
https://github.com/microsoft/navcontainerhelper/issues/3903
You may encounter this error while creating container or when you use Get-BCArtifact
Error querying artifacts. Error message was The remote server returned an error: (404) Not Found.
Solution
To fix the error you just need to update your bccontainerhelper module using the below commond
Update-Module bccontainerhelper -force
The above update will resolve the issue for some users but some of use who are using old powershell scripts in Azure DevOps pipelines you need to update the script in Install-BCContainerHelper.ps1, I have added the script in the above Github issue but you can also copy the below script and replace it
Param(
[string] $bcContainerHelperVersion = "",
[string] $genericImageName = ""
)
if ($bcContainerHelperVersion -eq "") { $bcContainerHelperVersion = "latest" }
if ($bccontainerHelperVersion -eq "dev") { $bccontainerHelperVersion = "https://github.com/microsoft/navcontainerhelper/archive/dev.zip" }
if ($bccontainerHelperVersion -like "https://*") {
$path = Join-Path $env:TEMP ([Guid]::NewGuid().ToString())
}
else {
$bcbaseurl = "https://bccontainerhelper.blob.core.windows.net/public"
$latestVersion = "latest"
$previewVersion = "preview"
if ($bccontainerHelperVersion -eq "latest") {
$bccontainerHelperVersion = $latestVersion
}
elseif ($bccontainerHelperVersion -eq "preview") {
$bccontainerHelperVersion = $previewVersion
}
$basePath = Join-Path $env:ProgramFiles "WindowsPowerShell\Modules\BcContainerHelper"
if (!(Test-Path $basePath)) { New-Item $basePath -ItemType Directory | Out-Null }
$path = Join-Path $basePath $bccontainerHelperVersion
$bccontainerHelperVersion = "$bcbaseurl/$bccontainerHelperVersion.zip"
}
$bchMutexName = "bcContainerHelper"
$bchMutex = New-Object System.Threading.Mutex($false, $bchMutexName)
try {
try { $bchMutex.WaitOne() | Out-Null } catch {}
if (!(Test-Path $path)) {
$tempName = Join-Path $env:TEMP ([Guid]::NewGuid().ToString())
Write-Host "Downloading $bccontainerHelperVersion"
(New-Object System.Net.WebClient).DownloadFile($bccontainerHelperVersion, "$tempName.zip")
Expand-Archive -Path "$tempName.zip" -DestinationPath $tempName
$folder = (Get-Item -Path (Join-Path $tempName '*')).FullName
[System.IO.Directory]::Move($folder,$path)
}
}
finally {
$bchMutex.ReleaseMutex()
}
. (Join-Path $path "BcContainerHelper.ps1")
if ($genericImageName) {
$bcContainerHelperConfig.genericImageName = $genericImageName
}
By following the steps outlined above, you can resolve the DownloadString error in your Azure DevOps pipelines. Keeping your modules and scripts up-to-date is essential to maintaining a smooth and error-free workflow.
For more details about the update or issue check Github Issue.
Leave a comment