Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

How to install PowerShell module pushed to Azure Artifacts in Pipelines?

Following this article I set up Pipelines to push a PowerShell module to my Artifacts feed.

I can install the module on my local machine, but I was wondering how I can do the same in Pipelines? It seems adding the NuGet source is an interactive process, so how can Pipelines add the Artifacts feed as a source?

The issue is that I don't want to have any user interaction in a CI environment.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are using self-hosted agent, you need to configure the folder module permission, self-hosted agent run the cmd via service account instead of personal account.

If you are using hosted agent, add the task power shell and enter below script to install the module.

$patToken = "$(pat)" | ConvertTo-SecureString -AsPlainText -Force

$credsAzureDevopsServices = New-Object System.Management.Automation.PSCredential("xxx", $patToken)


Register-PSRepository -Name "PowershellAzureDevopsServices" -SourceLocation "https://pkgs.dev.azure.com/{Org name}/{project name}/_packaging/{feed name}/nuget/v2" -PublishLocation "https://pkgs.dev.azure.com/{Org name}/{project name}/_packaging/{feed name}/nuget/v2" -InstallationPolicy Trusted -Credential $credsAzureDevopsServices

Get-PSRepository

Find-Module -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices


Install-Module -Name Get-Hello -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices


Get-Module -ListAvailable Get-Hello

Result:

enter image description here

Update1

We need to enter the code during the registration of the power supply enclosure repository, the method is Register-PSRepository

This is a certification issue, If we change the authentication method, maybe we don’t need to enter the code.

In addition, We could also install the module via the cmd Install-Module Get-Hello -Scope CurrentUser -Force


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...