Publish a PowerShell Module in an Azure Artifacts Nuget Feed
In this article I will show you how to use YAML pipelines to build and publish your custom PowerShell module to an internal Nuget Feed, hosted in Azure Devops (Azure Artifacts).
The Setup Repo Template
Notice on line 25–26 we register the same PackageSourceUrl
. When we set up this repository, we can use the same private feed to install any private dependency modules to build our new custom module during the pipeline job.
Also notice the ${{ format .. }}
expressions, this is required to get parameter values inside an inline Powershell script, 👉see my past article for more details about YAML templating.
You could use this inline script as a standalone script, just replace the format
expressions with a param()
block.
The Main Template
In your main template, call the above Template like this:
- template: azure-pipelines-setup-azdo-psrepo.steps.yml
parameters:
packageSourceUrl: <AzArtifactFeedUrl>
pat: $(System.AccessToken)
Where AzureArtifactFeedUrl
is the url of the Feed you create in the Azure Artifacts section of the project
📌 Note: You have to use version 2 to make this work.
To get the feed url, click the big Connect To Feed button, and copy the url in the first snippet, and change and trim the v3/index.json
to v2
Now you are ready to publish the module to the feed by using this command in a PowerShell step:
Publish-Module -Path <PathToMoDule> -Repository AzDoPSRepo -NuGetApiKey $(System.AccessToken)
Use the same name for the Repository as in the setup. Since it’s a private feed you need to authenticate using the NugeApiKey
.$(System.AccessToken)
is an built-in variable thats available during the pipeline (✋ you have to use persistCredentials
in the checkout step to make it available though)