azure-devopsrust-cargo

Does Azure DevOps cargo artifact feed support cargo search?


As part of my build validations I want my pipeline to check that the version number in a feature branch of my lib crate is strictly greater than the previously published version on my cargo feed. This is to ensure that after a PR has been merged, publishing the crate doesn't fail because the version number wasn't bumped.

To get the remote version number I have tried using cargo search but it seems like it's not supported as it always responds with a 404 saying:

error: failed to retrieve search results from the registry at https://pkgs.dev.azure.com/{organisation}/cf4789c3-fe81-4003-8668-deadbeef/_packaging/d7cc3967-810b-43cb-bc0e-deadbeef/cargo

Is cargo search not supported yet? If so, is there a plan to support it in the future?

Is there a different way I could achieve my goal?


Solution

  • I can reproduce the same issue when using the cargo search command. After successful authentication, it returns a 404 error.

    enter image description here

    I am afraid that the cargo search command doesn't support using Azure DevOps artifacts feed.

    You can submit a suggest ticket in the site: Developer Community which is our main forum for product suggestions to report this feature.

    Is there a different way I could achieve my goal?

    To meet your requirement, you can consider using the Azure DevOps Rest API to get the package versions: Artifact Details - Get Packages

    GET https://feeds.dev.azure.com/{organization}/{project}/_apis/packaging/Feeds/{feedId}/packages?includeAllVersions=true&api-version=7.1
    

    Here is the Powershell script sample:

    $token = "PAT"
    
    $Org = "Orgname"
    
    $Project = "ProjectName"
    
    $feedname = "feedname"
    
    $Packagename = "packageName"
    
    $GetFeedurl="https://feeds.dev.azure.com/$($Org)/$($Project)/_apis/packaging/feeds?api-version=7.1"
    
    $token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
    
    $response = Invoke-RestMethod -Uri $GetFeedurl -Headers @{Authorization = "Basic $token"} -Method Get  -ContentType application/json
    
    foreach($feed in $response.value)
    {
        if($feed.name -eq $feedname)
        {
           $feedid = $feed.id
        }
    }
    
    
    
    $GetPackage ="https://feeds.dev.azure.com/$($Org)/$($Project)/_apis/packaging/Feeds/$($feedid)/packages?includeAllVersions=true&api-version=7.1"
    
    $response1 = Invoke-RestMethod -Uri $GetPackage -Headers @{Authorization = "Basic $token"} -Method Get  -ContentType application/json
    
    
    foreach($package in $response1.value)
    {
        if($package.name -eq $Packagename)
        {
           $versions= $package.versions.version
        }
    }
    
    echo $Packagename
    
    echo $versions
    

    Result:

    Feed Package versions:

    enter image description here

    Script Output:

    enter image description here