by Lewis
Posted on January 1, 2018 at 12:00 PM
This article discusses using Azure DevOps as a Nuget source for TeamCity. This configuration was required to support differing versions of tools that supported differing NuGet versions.
Recently I’ve had a situation where I was using an older version of TeamCity, and the most recent version of Octopus deploy. With the more recent Octopus versions, Octopus is unable to consume NuGet v1 package feeds. This caused a problem as the version of TeamCity we were using only produced a v1 feed and there were no plans to upgrade as we were moving to Azure DevOps as our CI\CD platform.
Azure DevOps produces a v2 & a v3 NuGet package feed, which our copy of Octopus could already connect to.
To allow us to deploy our older products, we needed to build our packages and push them to Azure DevOps, whereby Octopus could connect, pull the package down and deploy.
In order to get TeamCity to connect to our Azure DevOps we need to configure a couple of things;
Configure a Personal Access Token
Use this page, set the following settings;
Name | Anything you want to refer to it as. |
Organisation | Leave as default |
Expiration | custom, set for a year |
Scopes | As I was testing, I set Scopes as Full Access. |
Press Create & on the page that is then displayed, copy the token and put somewhere safe for now. This token is not obtainable after you close this page.
This can be added in two ways. The more permanent solution is to add it directly to your build machine alternatively you can register\unregister the source. The latter method is described further in the article;
Add directly to build machine
nuget.exe sources add -name {your feed name} -source {your feed URL} -username {anything} -password {your PAT}
Close the command window & Log out
Navigate to TeamCity
In the build steps of the project, add a “NuGet Publish” step after your NuGet package step.
This build step will push the package you built to Azure DevOps. Change the settings as follows;
Runner Type | NuGet Publish |
Step Name | Anything you want |
Execute | If all previous steps finished successfully |
NuGet.exe | Latest version (at least 3.3) |
Packages | This is the path on your build server to your built nuget package. |
API key | Your PAT |
Package Source | Url to your nuget feed |
Alternatively, if you prefer not to have a custom package source on your build machine, you can add two further build steps to your build process;
This step should be added just before the step added previously to push the package to Azure DevOps.;
Step name | Anything you want |
Run | Executable with parameters |
Command executable |
The path to the latest version of nuget. On my install, version 4.7.1 has been added so my command looks like; %teamcity.tool.NuGet.CommandLine.4.7.1.nupkg%\tools\NuGet.exe |
Command parameters |
This is the most important bit, it registers your custom package URL with nuget using the PAT you obtained earlier; sources add -name {your feed name} -source {your feed URL} -username {anything, but I do use my Azure DevOps email} -password {your PAT} |
After we have done building, we want to remove the package source from NuGet. To do so, add a further build step after the push step;
Add “Command Line” build step
Modify the following;
Step name | Anything you want |
Run | Executable with parameters |
Command executable |
The path to the latest version of nuget. On my install, version 4.7.1 has been added so my command looks like; %teamcity.tool.NuGet.CommandLine.4.7.1.nupkg%\tools\NuGet.exe |
Command parameters |
This is the most important bit, it unregisters your custom package URL with nuget using the PAT you obtained earlier; sources remove -name {your feed name} |
Complete TeamCity build process
Once everything has been configured and you have implemented your preferred way of adding the VSTS source, you should kick a build off. Using the dashboard you should see all steps complete, once we are happy we can finish this configuration by updating Octopus.
For this implementation, the Octopus change was just a matter of going into my deployments and modifying where the package source came from using the drop down. I didn’t need to configure the Package Source as this had already been completed. For those that may need to do this, the steps are as follows;
Change the following:
Feed Type | NuGet Feed |
Name | Anything you want |
URL | The URL for your nuget package feed |
Credentials | These are the credentials required to access your feed. [Check if this is a PAT] |
Press Save & this connection is now available to use.