Overview
Azure Artifacts provides integrated package management for Maven, npm, NuGet, and Python packages. This tutorial shows how to publish and consume packages within an Azure Pipelines CI/CD workflow.
Prerequisites
- Azure DevOps organization with a project
- Azure Pipelines enabled
- Access to a repository containing your source code
Step 1 – Create an Azure Artifacts Feed
- Navigate to Artifacts in your project.
- Click New feed, give it a name (e.g.,
my-feed), and set visibility.
Step 2 – Configure Pipeline to Publish Packages
Below is a sample azure-pipelines.yml that builds a .NET project and publishes a NuGet package to the feed.
trigger:
- main
variables:
buildConfiguration: 'Release'
feedName: 'my-feed'
pool:
vmImage: 'windows-latest'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
- script: dotnet restore
displayName: 'Restore NuGet packages'
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'Build solution'
- script: dotnet pack --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)
displayName: 'Pack NuGet package'
- task: NuGetCommand@2
inputs:
command: 'push'
publishVstsFeed: '$(feedName)'
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
versioningScheme: 'off'
Step 3 – Consume Packages from the Feed
Add the feed to your nuget.config or use the dotnet restore command with the --source option.
<configuration>
<packageSources>
<add key="MyFeed" value="https://pkgs.dev.azure.com/YourOrg/YourProject/_packaging/my-feed/nuget/v3/index.json" />
</packageSources>
</configuration>
Step 4 – Set Up Permissions
| Role | Permissions |
|---|---|
| Project Administrators | Full access |
| Contributors | Publish & consume |
| Readers | Consume only |
Best Practices
- Use semantic versioning for packages.
- Lock feed access to specific groups.
- Enable retention policies to clean up old packages.