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

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

Answers


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.


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.


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.


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.


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>

Extending King Roger's answer ... the postman REST client chrome extension is an easy way to achieve it with little tooling.

> HTTP GET to http://servername:port/httpAuth/app/rest/builds/

Output will look like

<builds count="100" nextHref="/httpAuth/app/rest/builds?count=100&amp;start=100">
    <build id="48459" number="1.0.187-nightly" ... etc

Search the output your build id, on the same tag as the build number you see in teamcity, then

> HTTP DELETE to http://servername:port/httpAuth/app/rest/builds/*theid*

I didn't need authorisation tags or any other headers, possibly as I was logged into teamcity in another window or we have configured teamcity to be open internally, but you may need to pop them into the url and headers.


As others have mentioned, JetBrains' suggested workaround is to the delete the build(s) that produced the artifact--that is, the NuGet package--that you want to delete.

With curl 7.3x (found on ubuntu and Git for Windows / msysgit), the following command deletes build number 42:

curl -v -u <username>:<password> -X DELETE http://teamcity:8111/httpAuth/app/rest/builds/42
  • Uses short options (-X instead of -request, -u instead of -user); the long options didn't work for me.
  • Omit :<password> if you want to be prompted for your password.
  • Response of HTTP/1.1 204 No Content indicates success.

Full documentation: http://confluence.jetbrains.com/display/TCD8/REST+API#RESTAPI-Generalinformation


In extension to King Roger's answer, I used slightly different way of composing request in Fiddler. I made a Get request to a particular Teamcity build and grabbed http headers from Chrome Developer tool. Copied and pasted them to Fiddler's request headers box. This way I didn't have to encode username and password.


Need Your Help

Postgres user does not exist?

macos postgresql

I have just installed Postgres and have been tinkering with it and various configurations for 1-2 hours.

After logout, if I push back button I can see the last page which requires login

ruby-on-rails ruby-on-rails-3 devise browser-cache

I have devise configured in my web application. I have problem with the following workflow: