We have improved the experience with PowerShellGet and private NuGet feeds by focusing on pain points using an Azure Artifacts feed.
We addressed pain points by enabling/documenting the following features:
- Non-PAT authentication for package management
- Credential persistence in Register-PSRepository
These improvements will effect the following cmdlets:
- Register-PSRepository
- Set-PSRepository
- Find-Module/Script
- Install-Module/Script
- Update-Module/Script
- Save-Module/Script
- Publish-Module/Script
What is Azure Artifacts and Why would I use it?
Azure Artifacts is an Azure DevOps service which introduces the concept of multiple feeds that you can use to organize and control access to your packages. In other words it is a place for storing and sharing packages with controlled access through Azure DevOps. A common use scenario for Azure Artifacts with PowerShellGet is for organizations which need a controlled access feed for sharing their private internal packages and vetted external packages within their organization. Package owners may also want to use Azure Artifacts as part of their CI/CD pipeline in Azure DevOps. For more information on Azure Artifacts, check out their documentation.
Getting started with Azure Artifacts with PowerShellGet
Since these fixes were introduced into PackageManagement, verify you have at least version 1.4.2 of the PackageManagement module
to do this run Get-InstalledModule PackageManagement
. If you do not have this version 1.4.2 or higher run the command
Update-Module PackageManagement
and then refresh your PowerShell session. You should also ensure you have an up to date version of PowerShellGet.
The next step is to create an Azure Artifacts feed, since Azure Artifacts is an Azure DevOps service you will need to create an Azure DevOps account if you don’t already have one.
Once you gave an account you can create an Azure Artifacts feed. To do this, follow these steps. Return here for instructions on how to connect to the feed and publish packages.
The other component you will need is the Azure Artifacts credential provider. The credential provider comes pre-installed with Visual studio, so if you have VS 15.9, you don’t need to install anything. Otherwise the steps for installing the credential provider, which are platform dependent are provided here.
To register your feed as a PSRepository you will need a name, source location, and
publish location. The name is what you will call the PSRepository and can be anything you chose
in this example we call it “myAzArtifactsRepo”. Your source location, and publish location will be the same uri and will be the
format: “https://pkgs.dev.azure.com/’yourorganizationname’/_packaging/’yourfeedname’/nuget/v2“.
You are now ready to register your Az DevOps feed as a PSRepository using the
following command:
Register-PsRepository myAzArtifactsRepo -SourceLocation "https://pkgs.dev.azure.com/'yourorganizationname'/_packaging/'yourfeedname'/nuget/v2" -PublishLocation "https://pkgs.dev.azure.com/'yourorganizationname'/_packaging/'yourfeedname'/nuget/v2"
When you run this command you will be prompted with a device flow url which will allow you to authenticate the repository. In general you have three main options for authentication:
-
- Register the repository without the
-Credential
parameter [see above] and use the device flow url. - Explicitly provide a credential. To do this use the
-Credential
parameter when you register the PSRepository and provide a personal access token (PAT). For more information on how to get a PAT check out the documentation. Note that if you chose this method the credentials will not be cached. - Configure an environment variable with your credentials. To do set the
VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
variable to
{"endpointCredentials": [{"endpoint":"https://pkgs.dev.azure.com/'yourorganizationname'/_packaging/'yourfeedname'/nuget/v2", "username":"yourusername", "password":"accesstoken"}]}
Note may need to restart the agent service or the computer before the environment variables are available to the agent. For assistance with this step check out the Artifacts Credential Provider GitHub.
- Register the repository without the
Let’s publish a PowerShell Gallery package to our Azure DevOps feed.
To do this, you need to first save the module then, publish it using the following commands:
<code>Save-Module -Name SHiPS -Repository PSGallery -Path '.' Publish-Module -path "path\to\module"\SHiPS -Repository myAzArtifactsRepo -NuGetApiKey <key-- any arbitrary string> </code>
Now that we have some packages let’s find and install them:
Find-module -name SHiPS -Repository myAzArtifactsRepo Install-Module -name SHiPS -Repository myAzArtifactsRepo
Now that you can manage packages on your feed, you may want to share it with other users. To manage the access to your feed use the feed settings in Azure Artifacts. For more information on this check out the documentation.
Getting Feedback
If you encounter any issues we would love to hear about it on our GitHub page.
Please file an issue letting us know what we can do to make your experience better.
The post Using PowerShellGet with Azure Artifacts appeared first on PowerShell.