Connect your Cargo project to an Azure Artifacts feed
Azure DevOps Services | Azure DevOps Server 2022
This article guides you through setting up your Cargo project, configuring the credential provider, and connecting to an Azure Artifacts feed.
Prerequisites
Product | Requirements |
---|---|
Azure DevOps | - An Azure DevOps organization. - An Azure DevOps project. - Download and install rustup. You'll need Cargo version 1.74.0 or later. |
Project setup
Sign in to your Azure DevOps organization, and navigate to your project.
Select Artifacts, and then select your feed from the dropdown menu.
Select Connect to feed, and then select Cargo from the left navigation pane.
Add the provided snippet to your cargo/config.toml in your source repository. Your config.toml file should resemble the following:
Project-scoped feed:
[registries] FEED_NAME = { index = "sparse+https://pkgs.dev.azure.com/ORGANIZATION_NAME/PROJECT_NAME/_packaging/FEED_NAME/Cargo/index/" }
Organization-scoped feed:
[registries] FEED_NAME = { index = "sparse+https://pkgs.dev.azure.com/ORGANIZATION_NAME/_packaging/FEED_NAME/Cargo/index/" }
Add the following snippet to your cargo/config.toml to replace the crates.io source with your feed. Replace the placeholder with your feed name:
[source.crates-io] replace-with = "FEED_NAME"
Configure a credential provider
To use Cargo with Azure Artifacts, you must first set up a default credential helper. See The Cargo Book for more details.
Add the following snippet to your %USERPROFILE%.cargo\config.toml. This sets a default credential helper for the user:
[registry]
global-credential-providers = ["cargo:token", "cargo:wincred"]
Log in to the registry
Sign in to your Azure DevOps organization, and navigate to your project.
Generate a Personal access token with Packaging > Read & write scopes to authenticate with your feed.
Run the following command to log in to your registry. Replace the placeholder with your feed's name, and provide the personal access token you created earlier when prompted:
"Basic " + [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("PAT:" + (Read-Host -MaskInput "Enter PAT"))) | cargo login --registry <FEED_NAME>