Skip to content

Latest commit

 

History

History
194 lines (129 loc) · 6.35 KB

File metadata and controls

194 lines (129 loc) · 6.35 KB
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

Publish Cargo packages with Azure Pipelines

[!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.

Prerequisites

  • 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.

Authenticate with a feed

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts, and then select your feed.

  3. Select Connect to feed, and then select Cargo from the left pane.

  4. 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>"
      
  5. Create a Personal access token with Packaging > Read & write scopes to authenticate with your feed.

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Pipelines, and then select your pipeline definition.

  3. 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"
  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Pipelines, select your pipeline definition, and then select Edit.

  3. Select the + sign to add a new task. Search for the Cargo Authenticate task, and then select Add to add it to your pipeline.

  4. 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.":::


Publish crates to a feed

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Pipelines, and then select your pipeline definition.

  3. 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)
  1. From your Azure DevOps project, select Pipelines, select your pipeline definition, and then select Edit.

  2. Select the + sign to add a new task, then add the Command line task to your pipeline definition.

  3. 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>
  4. 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.":::


Example

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: Publish
trigger:
- 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: Publish

Once 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.":::

Related articles