| title | Publish Cargo packages with Azure Pipelines |
|---|---|
| description | Learn how to publish Cargo packages to an Azure Artifacts feed with Azure Pipelines. |
| ms.subservice | azure-devops-pipelines-artifacts |
| ms.author | rabououn |
| author | ramiMSFT |
| ms.topic | quickstart |
| ms.date | 12/17/2024 |
| monikerRange | >= azure-devops-2022 |
| recommendations | true |
[!INCLUDE version-gt-eq-2022]
Azure Pipelines enables developers to publish Cargo packages to Azure Artifacts feeds and public registries such as Crates.io. In this article, you will learn how to publish your Cargo packages to an Azure Artifacts feed using both YAML and Classic pipelines.
-
An Azure DevOps organization and a project. Create an organization or a project if you haven't already.
-
An Azure Artifacts feed. Create a feed if you don't have one already.
-
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Artifacts, and then select your feed.
-
Select Connect to feed, and then select Cargo from the left pane.
-
Copy the provided snippet from the Project setup section and add it to your config.toml file in your source repository. You file should look like this:
-
Project-scoped feed:
[registries] <FEED_NAME> = { index = "sparse+https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/Cargo/index/" } [source.crates-io] replace-with = "<FEED_NAME>" -
Organization-scoped feed:
[registries] <FEED_NAME> = { index = "sparse+https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/Cargo/index/" } [source.crates-io] replace-with = "<FEED_NAME>"
-
-
Create a Personal access token with Packaging > Read & write scopes to authenticate with your feed.
-
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Pipelines, and then select your pipeline definition.
-
Select Edit, and then add the following snippet to your YAML pipeline.
- task: CargoAuthenticate@0 displayName: 'Cargo Authenticate' inputs: configFile: '.cargo/config.toml' ## Path to the config.toml file that specifies the registries you want to work with. Select the file, not the folder e.g. "/.cargo/config.toml"
-
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Pipelines, select your pipeline definition, and then select Edit.
-
Select the
+sign to add a new task. Search for the Cargo Authenticate task, and then select Add to add it to your pipeline. -
Select the ellipsis icon to open a new window displaying your repository contents, and then choose your config.toml file.
:::image type="content" source="media/cargo-publish-classic.png" alt-text="A screenshot displaying how to configure the Cargo authenticate task in a Classic pipeline.":::
-
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Pipelines, and then select your pipeline definition.
-
Select Edit, and then add the following snippet to your YAML pipeline.
- powershell: | cargo publish --registry <FEED_NAME> ## Replace the placeholder with your feed name env: SYSTEM_ACCESSTOKEN: $(system.accesstoken)
-
From your Azure DevOps project, select Pipelines, select your pipeline definition, and then select Edit.
-
Select the
+sign to add a new task, then add the Command line task to your pipeline definition. -
Give your task a name, and then paste the following command into the Script textbox, replacing the placeholder with your feed name:
cargo publish --registry <FEED_NAME>
-
Select your agent job, scroll down to Additional options, and make sure you check the Allow scripts to access the OAuth token checkbox.
:::image type="content" source="media/publish-crate-cl-pipeline.png" alt-text="A screenshot displaying how to configure the publish task in a Classic pipeline.":::
The following example shows how to install Rustup on the agent, configure the PATH environment variable, build the project, authenticate with CargoAuthenticate, and publish to an Azure Artifacts feed:
trigger:
- main
pool:
vmImage: windows-latest
steps:
- powershell: |
Invoke-WebRequest -Uri https://sh.rustup.rs -OutFile rustup-init.sh
bash .\rustup-init.sh -y
echo "##vso[task.prependpath]$env:USERPROFILE\.cargo\bin"
displayName: Install
- task: CargoAuthenticate@0
displayName: 'cargo Authenticate'
inputs:
configFile: '.cargo/config.toml'
- script: |
cargo build --all
displayName: Build
- powershell: |
cargo publish --registry CargoInternalFeed
displayName: Publishtrigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- script: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
echo "##vso[task.prependpath]$HOME/.cargo/bin"
displayName: Install
- task: CargoAuthenticate@0
displayName: 'cargo Authenticate'
inputs:
configFile: '.cargo/config.toml'
- script: |
cargo build --all
displayName: Build
- powershell: |
cargo publish --registry CargoInternalFeed
displayName: PublishOnce your pipeline run completes, your crate should be available in your feed, as shown below:
:::image type="content" source="media/published-crate-to-feed.png" alt-text="A screenshot showing the hello-world-cargo crate published to the feed.":::