在自托pipe的VSO代理上运行NPM

我使用Azure上的Azure VM和Visual Studio Release插件build立了VSO代理。 我还安装了最新版本的node.js(使用NVM for windows)。 我在安装VSO代理时使用了默认帐户,因为我用于远程桌面的凭据不起作用。

我可以远程进入机器,并运行我试图从VSO运行的构build脚本。 我也可以运行纯粹的.NET构build与它的罚款。 我的问题是使用npm来安装我的软件包并运行构build。

我已经build立了这样的需求:

npm | exists

我已经在控制面板上设置了VSO代理的function,如下所示:

npm | C:\Program Files\nodejs\npm.cmd

也试过了

npm | C:\Program Files\nodejs

我可以在该文件夹中看到npm.cmd,当我远程使用该path时,我可以运行npm。 我也按照这个问题重新启动了VSO代理服务:

TFS构build代理无法findnpm

重新启动服务器,并做了几次“更新所有代理”。 我的path中也有npm,login后能正常执行。

编辑:

错误信息:

 npm : The term 'npm' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\work-folder\1\s\azure-deploy.ps1:24 char:1 + npm update + ~~~ + CategoryInfo : ObjectNotFound: (npm:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException 

我也尝试添加如下所述的行:

$env:Path += ";C:\Program Files\nodejs\"

同样的错误。 我的$ env:Path写入Write-Host写入该命令后给出:

 C:\Application Intallers\agent (1)\agent\worker\Modules\Microsoft.TeamFoundation.DistributedTask.Task.Internal\NativeBinaries\amd64;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Users\propertyplotdev\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI\wbin;C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy;C:\Program Files\nodejs;C:\Windows\ServiceProfiles\LocalService\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin;C:\Windows\ServiceProfiles\LocalService\.dnx\bin;C:\Program Files\nodejs\ 

C:\Program Files\nodejs\npm.cmdC:\Program Files\nodejs\node.js存在,NETWORK SERVICE对它们有权限。 (除了Adiministrators,SYSTEM和我的login)

解决scheme是使用常规安装程序安装node.js:

https://nodejs.org/en/download/

然后这工作。 还有其他的问题可以直接在这个问题上解决,不用nvm来安装节点。 然后,我可以在VSO构build定义界面中添加一个npm任务。

确保npm安装在“C:\ Program Files \ nodejs \”文件夹中,然后在PowerShell脚本中添加以下内容:

 $env:Path += ";C:\Program Files\nodejs\" 

尝试添加run npm命令构build任务:

添加构build步骤 – >添加任务 – >包 – > npm(运行npm命令)

并将install作为命令将web-project 目录作为工作目录

否则,请尝试添加以下function:

 node.js | C:\Program Files\nodejs\node.exe 

和:

  npm | C:\Program Files\nodejs\npm.cmd