How to remove a specific version of a package on a TeamCity Nuget Feed?

15,776

Solution 1

This is now supported through the Web UI

Just remove the offending build by opening the build and choosing Actions > Remove. This removes the build from the list in TeamCity, and it also removes all build artifacts of that specific build from the Nuget feed.

Solution 2

I know this was asked a long time ago but I still come across this problem every now and again and I always forget how to do it so I figured I would post my solution which I think might be slightly easier (depending on what way you look at it).

Basically, I ran a TeamCity build that unfortunately created a duff version of a 3rd party package that I tried to recreate but with a couple of modifications. It didn't work but it meant that I was always being presented with this duff package within the package manager and it will remain like this until the 3rd party releases a newer version. As such I wanted to delete the package from the TeamCity Nuget server and the only way I could find to do this was to delete the build which would also delete the artefacts (the duff Nuget package in this case).

Now, I couldn't see a way of deleting the build except with the REST API so that's what I used (I hope I'm not being stupid and there actually is an easy way of deleting builds from the UI). I used fiddler to generate the DELETE command. This was acheived by simply posting a delete request similar to what I've shown below:

From fiddler go to the Composer window. Select 'DELETE' instead of 'GET' and enter your TeamCity url in the form below:

http://<server>:<port>/httpAuth/app/rest/builds/<build ID>

The build ID can be found by simply inspecting the URL when you select the build you want to delete from TeamCity (look for the number after the 'buildId' query parameter). The only other step was to add the authorization header to the command. Enter the following on the line below 'User-Agent' in the Request Headers window.

Authorization: Basic (Username:Password encoded as base64)

To encode your username/password as base64 go to Tools->Text Wizard in fiddler and enter your TeamCity details in this format - Username:Password. Finally, you should select the 'Execute' button and all being well the build will get deleted along with the Nuget package.

This worked for me but obviously be careful when doing all this as you don't want to delete the wrong build. It may be prudent to backup/snapshot your TeamCity server first.

Hope this helps someone.

Solution 3

First off, it appears that deleting ad-hoc NuGet packages is not directly supported in TeamCity yet. There is an open issue with JetBrains about it, but there is no fix currently planned. That said, we devised a work-around that got us past our specific problem, and may help with yours.

We had a series of nupkg files that used an incorrect (accelerated) version. Thus, they appeared to be "newer" than the packages we are creating now. Without a way to remove only the incorrect versions, we set each individual TeamCity build-configuration's "Clean Artifacts" policy to a short window (2 days) and ran Clean-up. You will need System Administrator privileges to do this.

This removed any artifacts one day older than the last artifact and cleaned out all our bad packages. We verified this through the NuGet command line List command. Since the more recent packages are correct, we are now only advertising good packages in our NuGet feed.

Admittedly, this is a "precision nuke" option and may not work for everyone. I hope TeamCity fully supports the NuGet command line API in the near future.

Solution 4

It is now the third time I find this post, because I have a similar problem. It turns out that the ticket with jetbrains was closed a long time ago - and TeamCity now (at least our version 9.1) directly supports this by opening the details for a specific build, click the "Actions" dropdown, and select "Remove...". This will remove the build from TeamCity as well as the artifacts from the nuget package repository - thus completely removing the need for calling the REST api in slightly convoluted ways.

Having posted this, I might even remember it myself, the next time I need to do this.

Solution 5

I created a powershell script to do this along the lines of King Rogers answer.

Save this script as tc_deletebuild.ps1 ...

param($build, $teamcityhost, $username, $password)

$encodedcredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password))

Invoke-WebRequest -Uri "http://$teamcityhost/httpAuth/app/rest/builds/id:$build" -Method Delete -Headers @{"Authorization"="Basic $encodedcredentials"}

... and execute from powershell with

.\tc_deletebuild.ps1 <buildid> <host> <username> <password>
Share:
15,776
Nate Birkholz
Author by

Nate Birkholz

Microsoft .Net software development specialist with a focus in service orientated architecture and web development. Particularly interested in object oriented programming, design pattern implementation and framework design principals. I'm a C# junky and I absolutely love learning about new features in .Net. Interested in applying my passion for programming to new and exciting business and/or personal software applications.

Updated on June 11, 2022

Comments

  • Nate Birkholz
    Nate Birkholz almost 2 years

    Does anyone know to remove a specific version of a package on a TeamCity Nuget Feed?