Azure DevOps nuget push fails but task shows as success

658 Views Asked by At

I have a pipeline that nuget restores, builds, packs and pushes to private nuget feed. The version is taken from the project file via a powershell script and then packed using this version. If I have a library with version 1.0.2 already pushed to nuget and then I run the pipeline again with the same version 1.0.2, I can see in the task logs that the 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

Why it says that is not already on the service as it is already in the nuget feed.

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

And then when it tries to post it fails and the task is marked as Success whereas it shouldn't because new pipeline was not completed successfully (push failed). If it was marked as failed we can see the issue and change the version number.

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

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

1

There are 1 best solutions below

0
On BEST ANSWER

I can reproduce the same situation when I enable the option: allowPackageConflicts: true in the Nuget Push task.

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

You can disable the option in Nuget Push task.

For example:

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

Refer to this doc about nuget task.