Azure DevOps nuget 推送失败但任务显示为成功

Azure DevOps nuget push fails but task shows as success

我有一个 nuget 恢复、构建、打包和推送到私有 nuget 提要的管道。该版本通过 powershell 脚本从项目文件中获取,然后使用该版本进行打包。如果我有一个版本为 1.0.2 的库已经推送到 nuget,然后我再次使用相同的版本 1.0.2 运行 管道,我可以在任务日志中看到 The feed already contains 'ClassLib.Test 1.0.2'.

Adding package ClassLib.Test.1.0.2.nupkg to feed a9ffca7e-1598-4649-8b23-f21d8b637802 on https://pkgs.dev.azure.com/myorgname/.
Trying to add package to feed without uploading.
Adding package to feed.
The package content is not already on the service.
Uploading package content.
Done uploading package content.
Adding package to feed.
POST (https://pkgs.dev.azure.com/myorgname/_apis/packaging/a9ffca7e-1598-4649-8b23-f21d8b637802/nuget/packages) failed. ActivityId: 3a735b86-e8f8-4518-ae8b-2b683985503b, HTTP Status: Conflict, AFD Ref: Ref A: 12C6D7DE48854EF7ADER1234FC736FF9 Ref B: DF%TREE3112 Ref C: 2022-03-24T09:59:06Z
Finishing: Push to Nuget Feed in Azure DevOps

为什么它说它还没有出现在服务中,因为它已经出现在 nuget 提要中。

The package content is not already on the service.
Uploading package content.
Done uploading package content.

然后当它尝试 post 时失败并且任务被标记为成功,而它不应该因为新管道未成功完成(推送失败)。如果它被标记为失败,我们可以看到问题并更改版本号。

Adding package to feed.
POST (https://pkgs.dev.azure.com/myorgname/_apis/packaging/a9ffca7e-1598-4649-8b23-f21d8b637802/nuget/packages) failed. ActivityId: 3a735b86-e8f8-4518-ae8b-2b683985503b, HTTP Status: Conflict, AFD Ref: Ref A: 12C6D7DE48854EF7ADER1234FC736FF9 Ref B: DF%TREE3112 Ref C: 2022-03-24T09:59:06Z

当出现上述问题情况时,我们如何做到失败而不是标记为成功?

当我在 Nuget 推送任务中启用选项 allowPackageConflicts: true 时,我可以重现相同的情况。

How can we do this to fail instead of marked as success when the above issue scenario occurs?

您可以在 Nuget 推送任务中禁用该选项。

例如:

- task: NuGetCommand@2
  displayName: 'NuGet push'
  inputs:
    command: push
    publishVstsFeed: 'feedname'
    allowPackageConflicts: false

请参阅有关 nuget task 的文档。