Unable to Install-Module 'PowerShellGet' from an Azure DevOps build pipeline #663
Description
So I'm running a build pipeline in Azure DevOps and one of the steps requires to install various packages, some from PSGallery and some from an internal feed. In order to do that the first thing I do is:
Install-Module 'PowerShellGet' -AllowClobber -RequiredVersion "2.2.5" -Force -Repository 'PSGallery' -SkipPublisherCheck
Install-Module 'PackageManagement' -Force -AllowClobber -RequiredVersion '1.4.3' -Repository 'PSGallery' -SkipPublisherCheck
After that I should be able to install the remaining packages.
The problem is that sometimes, PowerShellGet
updates and sometimes it doesn't. Which makes it a pain to debug and determine what works and what doesn't.
I know a bug report should have a deterministic repro step process, but I don't have one. Sometimes it fails and sometimes it doesn't.
I have seen this fail in the past and I've resolved it by simply opening a new PowerShell instance, but that's not possible (Or at least I don't know how to do it) in an Azure DevOps build pipeline.
Steps to reproduce
Install-Module 'PowerShellGet' -AllowClobber -RequiredVersion "2.2.5" -Force -Repository 'PSGallery' -SkipPublisherCheck
Install-Module 'PackageManagement' -Force -AllowClobber -RequiredVersion '1.4.3' -Repository 'PSGallery' -SkipPublisherCheck
if it fails, it fails with the following warning:
WARNING: The version '1.4.7' of module 'PackageManagement' is currently in use. Retry the operation after closing the
applications.
Expected behavior
After running the install the following code should output "2.2.5" as the version
$module = Get-Module PowerShellGet
Write-Host "PowerShellGet version: "
Write-Host $module.Version.ToString()
Actual behavior
Sometimes it outputs 2.2.5
and sometimes 1.0.0.1
. Which means it has failed to update.