Skip to main content

Azure Artifacts


1 - Overview

Azure Artifacts lets you create, host, and share packages with your team and organization.


2 - Supported package types

TypeDescriptionPublic registry
npmJavaScript/Node.jsnpmjs.com
NuGet.NETnuget.org
MavenJavaMaven Central
Pythonpip packagesPyPI
UniversalBinary files-
CargoRustcrates.io

3 - Create a Feed

3.1 Via the interface

  1. Go to Artifacts
  2. Click "Create Feed"
  3. Configure the name and visibility

3.2 Via CLI

# Créer un feed
az artifacts feed create \
--name my-packages \
--organization https://dev.azure.com/MonOrg \
--project MonProjet \
--visibility organization

# Lister les feeds
az artifacts feed list

3.3 Visibility scopes

ScopeDescription
ProjectVisible only within the project
OrganizationVisible across the entire organization

4 - npm Packages

4.1 .npmrc configuration

# .npmrc (dans le projet)
registry=https://pkgs.dev.azure.com/MonOrg/MonProjet/_packaging/my-feed/npm/registry/
always-auth=true

4.2 Authentication

# Via Azure CLI (génère le token)
az artifacts universal download --help

# Ou via Personal Access Token
# Encoder: echo -n "PAT_TOKEN" | base64
# .npmrc avec auth
//pkgs.dev.azure.com/MonOrg/MonProjet/_packaging/my-feed/npm/registry/:username=MonOrg
//pkgs.dev.azure.com/MonOrg/MonProjet/_packaging/my-feed/npm/registry/:_password=BASE64_PAT
//pkgs.dev.azure.com/MonOrg/MonProjet/_packaging/my-feed/npm/registry/:[email protected]
//pkgs.dev.azure.com/MonOrg/MonProjet/_packaging/my-feed/npm/:username=MonOrg
//pkgs.dev.azure.com/MonOrg/MonProjet/_packaging/my-feed/npm/:_password=BASE64_PAT
//pkgs.dev.azure.com/MonOrg/MonProjet/_packaging/my-feed/npm/:[email protected]

4.3 Publish a package

# package.json
{
"name": "@monorg/my-package",
"version": "1.0.0"
}

# Publier
npm publish

4.4 npm pipeline

steps:
- task: npmAuthenticate@0
inputs:
workingFile: '.npmrc'

- script: npm ci
displayName: 'Install dependencies'

- script: npm publish
displayName: 'Publish package'
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')

5 - NuGet Packages

5.1 nuget.config configuration

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="my-feed" value="https://pkgs.dev.azure.com/MonOrg/MonProjet/_packaging/my-feed/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>

5.2 NuGet pipeline

steps:
- task: NuGetToolInstaller@1

- task: NuGetAuthenticate@1

- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'

- task: NuGetCommand@2
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'my-feed'

6 - Maven Packages

6.1 pom.xml configuration

<distributionManagement>
<repository>
<id>my-feed</id>
<url>https://pkgs.dev.azure.com/MonOrg/MonProjet/_packaging/my-feed/maven/v1</url>
</repository>
</distributionManagement>

<repositories>
<repository>
<id>my-feed</id>
<url>https://pkgs.dev.azure.com/MonOrg/MonProjet/_packaging/my-feed/maven/v1</url>
</repository>
</repositories>

6.2 settings.xml

<servers>
<server>
<id>my-feed</id>
<username>MonOrg</username>
<password>PAT_TOKEN</password>
</server>
</servers>

7 - Python Packages

7.1 pip configuration

# pip.conf
[global]
index-url=https://pkgs.dev.azure.com/MonOrg/MonProjet/_packaging/my-feed/pypi/simple/

7.2 Publish with twine

# Installer twine
pip install twine

# Publier
twine upload -r my-feed dist/*

7.3 Python pipeline

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'

- task: TwineAuthenticate@1
inputs:
artifactFeed: 'MonProjet/my-feed'

- script: |
pip install twine
python setup.py sdist bdist_wheel
twine upload -r my-feed --config-file $(PYPIRC_PATH) dist/*

8 - Universal Packages

For binary files that are not standard packages.

8.1 Publish

az artifacts universal publish \
--organization https://dev.azure.com/MonOrg \
--project MonProjet \
--feed my-feed \
--name my-binary \
--version 1.0.0 \
--path ./dist/

8.2 Download

az artifacts universal download \
--organization https://dev.azure.com/MonOrg \
--project MonProjet \
--feed my-feed \
--name my-binary \
--version 1.0.0 \
--path ./download/

8.3 Pipeline

steps:
- task: UniversalPackages@0
inputs:
command: 'download'
downloadDirectory: '$(System.DefaultWorkingDirectory)'
feedsToUse: 'internal'
vstsFeed: 'MonProjet/my-feed'
vstsFeedPackage: 'my-binary'
vstsPackageVersion: '1.0.0'

9 - Upstream Sources

9.1 Configure upstream sources

Lets you access public packages through your feed:

  1. Go to Feed Settings
  2. Upstream sources
  3. Add npmjs.com, nuget.org, etc.

9.2 Benefits

  • Caching of public packages
  • Version control
  • Availability even if the public registry is down
  • Security (scanning)

10 - Retention Policies

# Configurer la rétention
az artifacts feed update \
--name my-feed \
--days-to-keep-recently-downloaded-packages 30

Summary

In this chapter, we learned:

  • The supported package types
  • Creating Feeds
  • The configuration for npm, NuGet, Maven, Python
  • Universal Packages
  • Upstream Sources
  • Retention Policies

Next step

In the next chapter, we will look at Azure Test Plans.

→ Next chapter: Azure Test Plans


← Back to the table of contents