Locate nuget.exe on agent from plugin

I am developing a TeamCity plugin with a simple build step. As part of the build step I need to locate nuget.exe on the agent and execute it. Nuget.exe exists on the agent and there is a parameter teamcity.tool.NuGet.CommandLine.DEFAULT that points to its location. 
When I iterate over all the parameters from the plugin, the nuget parameter does not exist. 

When I use getToolPath method, it throws exception: 

Unable to find tool by name: NuGet.exe, there are no tool providers registered for this name. 
at jetbrains.buildServer.agent.impl.BuildRunnerContextImpl.getToolPath(BuildRunnerContextImpl.java:163) 
at com.citi.atom.deployment.teamcity.deploymentPlugin.AtomDeploymentBuildProcess.waitFor(AtomDeploymentBuildProcess.java:67)
at jetbrains.buildServer.agent.impl.buildStages.runnerStages.start.CallRunnerStage.doBuildStage(CallRunnerStage.java:75)
at jetbrains.buildServer.agent.impl.buildStages.RunnerStagesExecutor$1.callStage(RunnerStagesExecutor.java:25)
at jetbrains.buildServer.agent.impl.buildStages.RunnerStagesExecutor$1.callStage(RunnerStagesExecutor.java:18)

Below is the code that I used to find nuget.exe tool path. Can you help me to find nuget.exe parameter on the agent?

public BuildFinishedStatus waitFor() {

Map<String, String> parameters = buildRunnerContext.getBuildParameters().getAllParameters();

for(Map.Entry<String,String> entry : parameters.entrySet()){ 
logger.message(entry.getKey() + "=" + entry.getValue()); 

String nugetPath = buildRunnerContext.getToolPath("NuGet.exe"); 
logger.message("nuget.exe tool path is" + nugetPath); 

1 comment
Comment actions Permalink
Official comment

Hi Boris,


Thank you for developing a TeamCity plugin!

buildRunnerContext.getBuildParameters() gets you only the env.* and system.* parameters. You can get default tool path via buildRunnerContext.getConfigParameters().get("teamcity.tool.NuGet.CommandLine.DEFAULT")

While you can get path to a given NuGet version on the agent via buildRunnerContext.getToolPath("NuGet.CommandLine.3.2.0"); usually you do not need it on the agent as you do not know what NuGet versions are available.

Regularly, you should allow user to select the version of the tool in the settings (of the build runner) and then get the parameter which in resolved state will already contain the path to the tool on the agent.

That can be done by adding the following into your settings editing JSP:

<jsp:include page="/tools/editToolUsage.html?toolType=NuGet.CommandLine&versionParameterName=YOUR_PARAMETER_NAME_TO_CONTAIN_PATH&class=longField"/>

Please sign in to leave a comment.