简体   繁体   中英

Run custom npm command in Powershell on VSTS hosted build agent

I need to iteratively run an npm command and want to do it from a PowerShell task in a VSTS build step. I cannot use "npm <command>" in PowerShell and have also tried to run commands using "C:\Program Files\nodejs\npm.cmd" "<command>" and Invoke-Expression "C:\Program Files\nodejs\npm.cmd" "<command>" in the PowerShell on the VSTS hosted build agent. How can I run npm commands from a PowerShell build step?

Additionally, the <command> is a custom script from my package.json file. It does not need to be custom. I only put it there to call in a custom npm VSTS build step.

You can call npm command directly through PowerShell task with Hosted agent.

Make sure the Working folder (package.json folder path) of PowerShell task is right.

Regarding custom script in package.json, you need to call it like npm run [script key] .

You can call the npm command with the Start-Process and supplying the arguments through -ArgumentList switch seperated by commas

example Start-Process npm -ArgumentList "run","build" -wait the -wait switch will wait for the task to be completed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM