Azure Artifacts in Azure Pipelines

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

Step 1 – Create an Azure Artifacts Feed

  1. Navigate to Artifacts in your project.
  2. 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

RolePermissions
Project AdministratorsFull access
ContributorsPublish & consume
ReadersConsume only

Best Practices