Error when executing Register-PSRepository command from Azure DevOps pipeline
laellyo opened this issue · 0 comments
Context
We have developed custom Powershell modules to ease the management of third party solutions from developers laptop and Azure DevOps pipelines.
We don't have any issues when registrating these modules from a local environment, however we have this error thrown when we register our NuGet repository a from Azure pipeline.
Steps to reproduce
We have created a YAML pipeline with a powershell step to register and install our custom powersell module.
The content of the powershell script is:
Write-Host "Agent configuration"
$PSVersionTable
Write-Host "Powershell module already installed"
Get-Module -ListAvailable PackageManagement, PowerShellGet
Write-Host "List available package providers"
Get-PackageProvider -ListAvailable
Write-Host "Account email used to access DevOps feed is $(devOpsFeedAccountEmail)"
$feedLocation = "https://pkgs.dev.azure.com/mycompany/_packaging/devops/nuget/v2"
Register-PSRepository "MyCompany-DevOps" `
-SourceLocation $feedLocation `
-PublishLocation $feedLocation `
-InstallationPolicy "Trusted"
# => Error is thrown during this Register-PSRepository step
Write-Host "Prepare credentials for account $(devOpsFeedAccountEmail) to access the DevOps feed."
$patToken = "$env:devOpsFeedAccountToken" | ConvertTo-SecureString -AsPlainText -Force
$credsAzureDevopsServices = New-Object System.Management.Automation.PSCredential("$(devOpsFeedAccountEmail)", $patToken)
Write-Host "Install and import the module MyCompany.Scripts to the current user session..."
Install-Module -Name XXXX.YYYYYY -Repository MyCompany-DevOps -Credential $credsAzureDevopsServices -Force -Scope CurrentUser
Import-Module MyCompany-Scripts -Force
Write-Host "Install and import OK!"
Expected behavior
Our custom NuGet repository should be correctly added.
Actual behavior
During the execution of the Register-PSRepository command, we obtain the following error.
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET program, but dotnet--V does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET program, but dotnet--V does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
Test-Path: Value cannot be null. (Parameter 'The provided Path argument was null or an empty collection.')
The root cause seems related to a path that is not correctly setup (Test-Path null Path argument), however I don't really understand why it is failing.
Thanks in advance for your help!
Environment data
❯ $PSVersionTable
Name Value
---- -----
PSVersion 7.2.2
PSEdition Core
GitCommitId 7.2.2
OS Linux 5.13.0-1021-azure #24~20.04.1-Ubuntu SMP …
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> Get-Module -ListAvailable PowerShellGet,PackageManagement
Name : PackageManagement
Path : /opt/microsoft/powershell/7/Modules/PackageManagement/Packa
geManagement.psd1
Description : PackageManagement (a.k.a. OneGet) is a new way to discover
Description : PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Modules, DSC Resources, Role Capabilities and Scripts.
Guid : 1d73a601-4a6c-43c5-ba3f-619b18bbb404
Version : 2.2.5
ModuleBase : /opt/microsoft/powershell/7/Modules/PowerShellGet
ModuleType : Script
PrivateData : {SupportedPowerShellGetFormatVersions, PSData, PackageManagementProviders}
AccessMode : ReadWrite
ExportedAliases : {[inmo, inmo], [fimo, fimo], [upmo, upmo], [pumo, pumo]}
ExportedCmdlets : {}
ExportedFunctions : {[Find-Command, Find-Command], [Find-DSCResource, Find-DSCResource], [Find-Module, Find-Module], [Find-RoleCapability,Find-RoleCapability]…}
ExportedVariables : {[PSGetPath, ]}
NestedModules : {}
> Get-PackageProvider -ListAvailable
Name : NuGet
ProviderName : NuGet
Features : {[supports-powershell-modules, System.Collections.Generic.List`1[System.String]], [file-extensions, System .Collections.Generic.List`1[System.String]], [uri-sch emes, System.Collections.Generic.List`1[System.String ]], [magic-signatures, System.Collections.Generic.Lis t`1[System.String]]}
Version : 3.0.0.1
ProviderPath : /opt/microsoft/powershell/7/Modules/PackageManagement/coreclr/netstandard2.0/Microsoft.PackageManagement.NuGetProvider.dll
SupportedFileExtensions : {nupkg}
SupportedUriSchemes : {http, https, file}
DynamicOptions : {Destination, ExcludeVersion, Scope, SkipDependencies}
FastPackageReference :
Source :
Status :
SearchKey :
FullPath :
PackageFilename :
FromTrustedSource : False
Summary :
SwidTags : {NuGet}
CanonicalId :
Metadata : {}
SwidTagText : <?xml version="1.0" encoding="utf-16" standalone="yes"?><SoftwareIdentity version="3.0.0.1" name="NuGet" xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd" />
Dependencies : {}
IsCorpus :
VersionScheme :
TagVersion :
TagId :
IsPatch :
IsSupplemental :
AppliesToMedia :
Meta : {}
Links : {}
Entities : {}
Payload :
Evidence :
Culture :
Attributes : {version,name}
Name : PowerShellGet
ProviderName : PowerShellGet
Features : {[supports-powershell-modules, System.Collections.Generic.List`1[System.String]]}
Version : 2.2.5.0
ProviderPath : /opt/microsoft/powershell/7/Modules/PowerShellGet/PSModule.psm1
SupportedFileExtensions : {}
SupportedUriSchemes : {}
DynamicOptions : {PackageManagementProvider, Type, Scope, AllowClobber…}
FastPackageReference :
Source :
Status :
SearchKey :
FullPath :
PackageFilename :
FromTrustedSource : False
Summary :
SwidTags : {PowerShellGet}
CanonicalId :
Metadata : {}
SwidTagText : <?xml version="1.0" encoding="utf-16" standalone="yes"?><SoftwareIdentity version="2.2.5.0" name="PowerShellGet" xmlns="http://standards.iso.or/g/iso/19770/-2/2015/schema.xsd" />
Dependencies : {}
IsCorpus :
VersionScheme :
TagVersion :
TagId :
IsPatch :
IsSupplemental :
AppliesToMedia :
Meta : {}
Links : {}
Entities : {}
Payload :
Evidence :
Culture :
Attributes : {version,name}