【问题标题】:Can't find Package in Azure Artifacts while using REST API使用 REST API 时在 Azure Artifacts 中找不到包
【发布时间】:2021-08-13 19:50:08
【问题描述】:

我正在使用 REST API 将包更新到另一个视图(推广),但我不断收到一个错误,即包在我的提要中不存在,我不知道为什么。

REST 调用 - 方法:PATCH

https://pkgs.dev.azure.com/MyOrg/_apis/packaging/feeds/5aa467a8-14d8-4590-8579-37d9769f6159/npm/testLib/versions/0.0.12345?api-version=6.1-preview.1

请求正文:

{
    "views":
    {
        "op":"add", 
        "path":"/views/-", 
        "value":"Test"
    }
}

这是我在 Postman 中遇到的错误

{
    "success": "false",
    "error": "NotFound",
    "reason": "Cannot find the file testLib-0.0.12345.tgz in package 'foundations 0.0.74965' in feed 'MyFeed'",
    "innerException": null,
    "message": "Cannot find the file testLib-0.0.12345.tgz in package 'foundations 0.0.74965' in feed 'MyFeed'",
    "typeName": "Microsoft.VisualStudio.Services.Packaging.Shared.WebApi.Exceptions.PackageNotFoundException, Microsoft.VisualStudio.Services.Packaging.Shared.WebApi, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    "typeKey": "PackageNotFoundException",
    "errorCode": 0,
    "eventId": 3000
}

【问题讨论】:

  • 你使用了正确的包名吗?在您的提要屏幕截图中,它似乎应该是 @ testlib,而您的 REST 调用仅使用 testLib
  • 这个问题有更新吗?如果答案能给你一些帮助,请随时告诉我。只是提醒this
  • @LeoLiu-MSFT 我添加了我的答案。希望它可以帮助其他人!

标签: rest azure-devops azure-artifacts


【解决方案1】:

在使用 REST API 时无法在 Azure Artifacts 中找到包

同意米尔布兰特。看来您应该提供 packageName @ testlib 而不是 testLib

您可以使用 REST API Artifact Details - Get Packages 列出此提要中的所有包:

GET https://feeds.dev.azure.com/{organization}/{project}/_apis/packaging/Feeds/{feedId}/packages?api-version=5.1-preview.1

【讨论】:

    【解决方案2】:

    所以我最终让它与以下代码一起工作

    $package = Get-Content -Path "$(Build.ArtifactStagingDirectory)/libs/${{ package.value }}/package.json" -Raw | ConvertFrom-Json
    
    $version = $package.version
    Write-Output "Updating ${{ package.key }} $version"
       
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "{Promoting npm package}","{$(System.AccessToken)}")))
    
    $uri = "https://pkgs.dev.azure.com/MyOrg/_apis/packaging/feeds/5aa467a8-14d8-4590-8579-37d9769f6159/npm/packagesbatch?api-version=6.1-preview.1"
    $viewURI = "https://feeds.dev.azure.com/MyOrg/_apis/packaging/Feeds/MYFEED/views/${{ parameters.environment }}?api-version=5.1-preview.1"
    
    Write-Output "Retrieving View from Azure Artifacts"
    $viewID = ((Invoke-WebRequest -Uri $viewURI -Headers @{Authorization="Bearer $(System.AccessToken)"} -Method Get).Content | ConvertFrom-Json).id
    
    $body = '{"data":{"viewId":"' + $viewID +'"},"operation":0,"packages":[{"id":"@cn/${{ package.key }}","version":"' + $version + '","protocolType":"Npm"}]}'
    
    Write-Output "Deploying ${{ package.key }} to Azure Artifacts"
    Invoke-WebRequest -Uri $uri -Headers @{Authorization="Bearer $(System.AccessToken)"} -Method Post -Body $body -ContentType "application/json" 
    

    目标是检索视图,获取视图 ID,将其注入主体以调用 packagesbatch REST 调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      • 2019-11-08
      • 2021-07-10
      • 1970-01-01
      • 2019-12-09
      • 2020-01-30
      相关资源
      最近更新 更多