running bower from TeamCity (Windows) - permissions

I've got a set of build steps in a project (Team City 9.0c)
One of them is running bower install which is a simple command line execution with no parameters.
Bower is installed on the system (I can run it just fine from the command prompt on the machine) but I get the following error
[10:47:35][Step 2/7] Starting: D:\TeamCity\buildAgent\temp\agentTmp\custom_script8385462966123630321.cmd
[10:47:35][Step 2/7] in directory: D:\TeamCity\buildAgent\work\5d43cd6017ab83d4\website\Amaze.Web
[10:47:37][Step 2/7] 'bower' is not recognized as an internal or external command,
[10:47:37][Step 2/7] operable program or batch file.
[10:47:37][Step 2/7] Process exited with code 1
[10:47:37][Step 2/7] Step Bower (Command Line) failed
I've seen this before where PATH is not set to the location of the npm binaries in c:\users\xxxx\roaming\... so the TC user cannot find them, however PATH is correct.
Both npm and grunt work successfully. What could be causing this?

Is the path variable defined a user variable? If so, it should be a system variable which will be used by the TeamCity process.

You haven't written which accounts the build agent runs as.
I had a similar problem and my build agent was running using Local System. I had to create a dedicated windows user account for the teamcity build agent, in the build script I added
npm install -g bower
set path=%path%;c:\path_to_bower_for_this_user;

Related

Azure DevOps - npm invisible

I have a strange problem with a release pipeline in Azure DevOps.
I have two tasks:
1) Install packages
2) Run npm using the above packages
All seems to be easy so what I do is:
1) Command line task
npm install -g mkdirp 1.0.3
npm install -g newman
npm install -g newman-reporter-junitfull
2) PowerShell task
$(newman run $collection -e $environment --env-var "x=$(x)" -r junit --reporter-junit-export $resultFile)
This all worked fine until today. I tried a lot, but nothing works.
The error I have is:
newman : The term 'newman' 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.
Did anyone have a similar issue?
I ran above npm install scripts in a Command line task, and found only the first npm install command got executed. And my following powershell task to run newman command failed with above error message too. You can check the log of Command line task to see if it is the same issue.
If you want to report this issue, you can report a problem here.
The workaround i found is to run the npm install commands in a Powershell task too, do not use Command line task. Then the npm install commands will all get executed and the following powershell task can run successfully.
Or you can separate above three npm install commands into three Command line tasks to install them separately, which will make sure the newman library is installed.

npm install when deploy Octopus

I need to create node_modules in the root app when deploy new version using Octopus
How can I create a run script using a new octopus step? I try:
npm install
But I get error when execute the script step
'The remote script failed with exit code 1'
Any ideas?
Your build system should be handling that for you. The node_modules directory should then be included in your application package, but ideally, this should also be bundled to reduce the number of files that your application is dependant on.
If you do need to run this as part of a deployment, then you would need NodeJS and npm installed on the server that is executing the deployment step (either the Octopus server itself or a worker instance if using workers).
For more information check out this blog post

NPM Package Error- 'newman' is not recognized as an internal or external command

I have installed the latest version of Newman (3.10.0) in my 64-Bit Win 10 Machine.
C:\Users\ABC>npm install -g newman
C:\Users\ABC\AppData\Roaming\npm\newman -> C:\Users\ABC\AppData\Roaming\npm\node_modules\newman\bin\newman.js
+ newman#3.10.0
added 195 packages in 57.852s
However, I am not able to use the newman and I am getting below error while accessing.
C:\Users\ABC>newman -h
'newman' is not recognized as an internal or external command,
operable program or batch file.
I have added an environment variable for the NODE_PATH pointing to the newman directory C:\Users\ABC\AppData\Roaming\npm\node_modules\newman
but no luck. Could some one please help.
Adding in the Path variable under Environment Variable solve the problem even if we don't add in NODE_PATH
C:\Users\ yourusername \AppData\Roaming\npm
After doing this reopen command prompt
The issue was fixed after troubleshooting with the Node Application. A previous version of Node (32-bit) was installed in my machine and it was not completely removed after I did an uninstall. When I installed Node 64-Bit both entry was present in the environment variable and caused a conflict.
When I manually deleted both installation folder and the env variable the newman worked correcly.
I have installed node, vc redist and newman once (on clear windows 7 64 bit) and the issue is looks like related to wrong newman installation. Both newman and node should be installed from administrator session (not just with admin privileges). I have installed newman from regular user, system path setting are correct, but user environment was not set:
path=C:\Users\gagarin\AppData\Roaming\npm
So I have copied
C:\Users\<regular_user>\AppData\Roaming\npm
to C:\Users\admin\AppData\Roaming\npm and run C:\Users\admin\AppData\Roaming\npm\newman.cmd from administrator session. After that newman command became work in admin session. Sadly it works in regular user session only if I type full path to newman like
Blockquote
c:> C:\Users\admin\AppData\Roaming\npm\newman run ....
I was also getting the same error and I have followed the below steps to troubleshoot it-
1. Know what user is running jenkins, a simple way is Create a jenkins job and in its Build section run the command
whoami
2. If it shows System user, then do the following-
2.a. Set C:\Users\I823285\AppData\Roaming\npm and C:\Users\I823285\AppData\Roaming\npm\node_modules\newman\bin in SYSTEM ENV. VARIABLES.
b. Restart Jenkins by running CMD as ADMIN, and go to Jenkins installation folder, then enter jenkins.exe restart.
c. Re-build the project
SUCCESSFUL!

Couldn't find a debug log in the cache or working directory

I want to create a VSTS build with npm package auditing capabilities using npm audit. I added a few tasks to run npm audit. The command runs and I can see the details in the console/logs for all the packages. However, the task fails complaining about not finding a logs file. Any idea on how I can get the builds to stop working if I find a high vulnerability package?
EDIT
This is the final line in the result when I run npm audit locally
Notice how it displays vulnerabilities in categories. I want the build to not proceed if there is a non-zero value for High vulnerability.
I got the same error, but then realize that I am using incorrect custom command for npm task:
it was "npm install gulp -g", but should be "install gulp -g" (without npm).
For me it helps.
There isn’t the way to stop/fail build directly if there is a non-zero value for High vulnerability.
The workaround is that you can do it through PowerShell with Build log REST api to analysis whether there is related information in the log, then fail the build (Write-error …) (Run the powershell through PowerShell task)

Visual Studio Code (Windows) Not Detecting Global NPM Modules

I'm experiencing an issue where Visual Studio Code in Windows 10 is not able to detect globally installed NPM packages within the Integrated Terminal.
For example, if the windows command prompt I install #angular/cli via command npm install -g #angular/cli, within that command prompt I can execute #angular/cli commands such as ng --version without error. After that global npm module install, within Visual Studio Code, performing the same ng --version gives me the error:
The term 'ng' 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.
I can however within the integrated terminal successfully perform commands such as npm -v and node -v.
I have the following items in my system environment variables
C:\Program Files\nodejs\
%AppData%\npm
Are there Visual Studio Code user or system environment variables I'm missing to allow detection of global npm modules?
Thank you for any help you can provide.
Visual Studio Code must be "Run as Administrator" for working Terminal Commands.
I was able to resolve the issue and use global npm commands in Visual Studio Code by modifying my system environment path variables to position %AppData%\npm before %ProgramFiles%\nodejs\ per npm troubleshooting tips
no need to do anything else just follow below steps -
right click on my computer (this pc).
go to properties.
click on advanced system setting.
click on environmental variable.
select path variable from system variable.
click on edit button.
add %AppData%\npm and %ProgramFiles%\nodejs\ at top of the list.
8 click on ok. ok. ok
restart your system.
after restart open visual studio code as run as administrative mode.
Enjoy...............!!!!!
Run Visual studio code as an administrator. Then type ng command. It should work
Reboot your computer , this worked for me
If you have entered the environment variable and it is still not recognized and if you don't want to reboot your computer because you have so many things running then just reboot your Visual Studio Or Visual Studio Code and then Open Terminal (ctrl + `) and run
npm install
Now it will work fine.
You can resolve the issue by opening the VS Code Terminal and type
npm install -g #angular/cli
This should resolve the issue.
Run powershell or cmd prompt in admin mode.
Check if npm and node commands work (if not, then check environment variables as others have mentioned).
Update node using npm [https://stackoverflow.com/questions/18412129/how-can-i-update-
npm-on-windows]
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
Run npm install -g #angular/cli
Run ng --version in Visual Studio Code to see if it's now working.
If you do not have access to Environmental variable (office machines).
You can try to run command like this:
npm run <your angular command>
it works as well, just need to add npm run before ng command
Example -> npm run ng g c shop/cart
I found that adding %AppData%\npm to your Path variable made it work for PowerShell and the Command Prompt, it still did not work for the integrated PowerShell in VS Code for me.
When I changed it from %AppData%\npm to the actual path C:\Users\<USER>\AppData\Roaming\npm where <USER> is your user directory, and reopened VS Code it started working.
Additionaly to all the good advice here, make sure that you have node.js installed on your machine.
To me the solution was adding the extensions for npm: