wedriverio jenkins - npm command not found error - node.js

I am trying to run webdriverio test from jenkins and following this . I installed nodeJS plugin for jenkins and under global tool config, for NodeJS , added a name and installation directory as /usr/local/bin (node executable is in this folder)
In Jenkins, in project config , under build environment, I have checked
Provide Node & npm bin/ folder to PATH and chosen the node installation name from previous step
But when I am trying to run npm install
npm test ,by adding these commands under execute shell under Build and building it, I receive this error
Building in workspace /Users/Shared/Jenkins/Home/workspace/wdio-project
[wdio-project] $ /bin/sh -xe /Users/Shared/Jenkins/tmp/hudson1478028169114509075.sh
+ npm install
/Users/Shared/Jenkins/tmp/hudson1478028169114509075.sh: line 2: npm: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

In case someone is looking for same issue, I resolved the above error by adding export PATH=/usr/local/bin to the execute shell under build. This post helped me

There is currently a bug opened about this (JENKINS-26583 and JENKINS-27170)
I could workaround this bug by adding explicitly node on the PATH by adding this line :
export PATH=$PATH:/home/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node_js/bin/

I had just fixed the same issue as you did.
I wonder if my fix would also help you. When I was using the alpine-based docker image, the Jenkins can never find the npm, but when I use the debian-based docker image, problem solved immediately.

Try this export PATH=/usr/local/bin:$PATH

After installation of NodeJS restart pc

In my case this worked -
export PATH=$PATH:/usr/local/bin

Related

ANY ng command will fail when trying angular due to invalid character error in ng file

The \AppData\Roaming\npm\node_modules#angular\cli\bin\ng.js file cannot be opened and it gives an error whenever I try to use an ng command anywhere, be it in an angular project or elsewhere.
The error is as follows:
Script: (my username)\AppData\Roaming\npm\node_modules#angular\cli\bin\ng.js
Line: 1
Character: 1
Error: Invalid Character
Code: 800A03F6
Source: Compilationerror Microsoft Jscript
What I have tried:
using ng commands in different project -- same error
reinstall npm, angular, removing the node modules in all combinations
Setting the angular path in the environment variables
What happened before:
ng command was missing possibly due to stuff related to python install. This error is replaced with my current problem when reinstall is done.
I have reinstalled everything to the fullest extent but the problem keeps persisting.
I can use my angular project by running 'npm run ng serve' and that weirdly works.
Does anyone have ANY idea what might cause this problem
EDIT:
I have somehow managed to resolve the problem but I have no clear answer what was the cause of it all. I did reinstall nodeJS on my computer which MIGHT have been broken during another project.
Remove the user environment variable
C:\Users\AppData\Roaming\npm\node_modules#angular\cli\bin
It worked for me after losing a day of life looking for a solution
In my case this error occured because of permissions on windows. Try to run cmd as Administrator.
Deleting and reinstalling node.js did not fix it. The issues started when I installed latest CLI which is 13.
I removed npm folder from C:\Users\username\AppData\Roaming then I installed the previous version
npm install -g #angular/cli#12.0.0
I do not get the error anymore.
What worked for me is setting this path:
set path=%PATH%;C:\Users{username}\AppData\Roaming\npm
Firstly you need to set the path of npm
$ npm config get prefix
make sure path matches with npm config get prefix
export PATH=/usr/local/share/npm/bin:$PATH
in windows you can set by advance system settings -> Environment variable -> set path.
Restart you system then do this -
$ npm install -g #angular/cli#latest
get package version
$ ng version
create workspace
$ ng new my-project
run the application
$ cd my-project
$ ng serve

Continuous integration and deployment of Node.js application on Bamboo

The application I want to implement continuous deployment on Bamboo has node modules and bower component dependencies. On the bamboo server nodejs, npm have been installed.
There are only three tasks on default job:
Source Code Checkout
Build dependencies:
npm install
bower install
Deploy to the staging server
The problem is on the second task, bamboo fails with the message "No failed tests found, a possible compilation error occurred." I don't even run any tests.
The log file is not explanatory at all:
Starting task 'Build dependencies' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
Failing task since return code of [/bin/sh /home/ubuntu/bamboo-installation/temp/WEB-WEB-JOB1-8-ScriptBuildTask-4430338079602360707.sh] was 1 while expected 0
Ok, I solved the problem. The issue was the wrong node (which obviously messed things up) was installed on the bamboo server. Uninstalled the wrong one and everything worked as expected.
Good to see you solved it.
There is a setup I use and which could prevent further problems with CI:
export npm_config_prefix=.npm/
export PATH=.npm/bin:$PATH
export CI=true
npm install -g bower
bower install
npm install
This installs bower (and others like grunt-cli if you want) in your project folder so you can e.g. have a specific version, sets CI=true as advised in bower docs, and then installs all dependencies.
Bamboo AMI originally have npm version 1.4.28 installed and you are probably using a more recent version on you development environment. I had the same issue and resolved it by creating a script task to update npm version on the very beginning of my build process. Here is the script:
# update npm
curl -O -L https://npmjs.org/install.sh
chmod +x install.sh
sudo PATH=$PATH:/opt/node-0.10/bin ./install.sh

Jenkins integration with Grunt

I've setup Jenkins v1.550 on Windows Server 2008 R2. It runs as a service at http://localhost:8080 for now. I'm logged into the machine as an Administrator. I've installed Node.js and can run "npm" from the command line.
I've also installed the NodeJS plugin v0.2.1 for Jenkins. I then went into the Configure System section of Jenkins, scrolled down to NodeJS installations, clicked on Add NodeJS button, gave "NodeJS" as the name, and "C:\Program Files\nodejs" as the path to the installation directory. I didn't check the "Install automatically" option as I read on the plugin page that it is only available to Linux.
I then created a new job, clicked the checkbox that said "Provide Node & npm bin/ folder to PATH", created a new build step for "Execute Windows batch command" and typed in "node --version" and "grunt --version" and saved it.
I ran the job and this is the output -
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Test_1.0
[Test_1.0] $ cmd /c call C:\Windows\TEMP\hudson1381541243088903083.bat
C:\Program Files (x86)\Jenkins\workspace\Test_1.0>node --version
v0.10.24
C:\Program Files (x86)\Jenkins\workspace\Test_1.0>grunt --version
'grunt' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files (x86)\Jenkins\workspace\Test_1.0>exit 9009
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
It looks like it's unable to find the grunt-cli for the user account Jenkins is running under (System). I tried to installing grunt cli globally (npm install -g grunt-cli) and also grunt locally (npm install grunt). No luck.
Can someone please help?
for nice easy to configure self-installed nodejs on the machine, i have to recommend the excellent -> http://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
it will install nodejs and grunt on the machine, through easy to use web front end no shell required
jenkins jobs can then simply run nodejs build steps, hey presto
steps involved :
a) install this on your jenkins instance -> http://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
b) create a nodejs installation on jenkins
go to
http://URL_OF_JENKINS/jenkins/configure
NodeJS- > NodeJS installations -> Add NodeJS -> Name = "NodeJS 0.11.10", tick "Install automatically", select "Install from nodejs.org", add "grunt-cli" to globally installed packages
c) create a job with "execute NodeJS script" build task
var sys = require('sys');
sys.puts('NodeJS Test');
sys.puts('***************');
sys.puts('helloworld');
volia :)
run the job and see the nodejs script run,
from their the world is your oyster you can use grunt by ticking "Provide Node/npm bin folder to PATH" and running a "execute shell" build task
npm update
grunt
grunt --force reporting
You will need to restart the Jenkins service after installing node, presumably to cause it to refresh its cached copy of your PATH environment variable
I have grunt doing some tasks for me in Jenkins, but I went the npm script route. Grunt and grunt-cli are dev dependencies, and I have the following defined in my package.json file:
"scripts": {
"test": "node node_modules/grunt-cli/bin/grunt test"
},
In Jenkins (running on Windows), I added two post-build tasks:
npm install
npm test
We just installed NodeJs normally on the Jenkins server.
Another solution that worked for me on Windows is to use the full path to the grunt exec file, which can be found by writing "where grunt" in the command shell. I used the full path in the regular bat-file.
Had the same issue on Windows. When I manually installed node and ran npm install -g grunt-cli from command line, jenkins could not recognize the grunt command. So uninstall node, reinstall it but dont run npm install. Then restart the jenkins slave. Then from the jenkins job that runs on your specific jenkins slave, make it run a Windows batch command that runs npm install -g grunt-cli After that again restart the jenkins service. Then from the job run npm install. Then everything worked for me. If issues still persist, then uninstall the slave, and reinstall it, then everything works fine immediately.

NodeJS/Testacular on Jenkins CI

I'm using Testacular which is a Node.js test runner for Angular/Jasmine. I can run it fine from the command line, but every time I try to run it from Jenkins build steps, it bombs out with all sorts of errors regarding environment variables. I tried the Nodejs plugin for Jenkins, but that's just to run node code snippets. Anyone know of a way to have node apps (eg. Testacular) running test under Jenkins?
You will need to:
have "testacular" as a dependency in your package.json file.
install your dependencies with npm install (do this as a build step)
call it as ./node_modules/.bin/testacular start --single-run
Assuming you have configured testacular to use PhantomJs browsers = ['PhantomJS'];, you just need to have the phantomjs binary in your path or tell testacular where it is located with an environment variable set in your shell:
export PHANTOMJS_BIN=$HOME/local/bin/phantomjs
good news!
" I tried the Nodejs plugin for Jenkins, but that's just to run node code snippets. "
nope!
install the nodejs plugin see instructions here -> NodeJS jenkins plugin broken?
then tick "Provide Node/npm bin folder to PATH" and when running a "execute shell" build task, you can use nodejs, here's a example using grui
npm update
grunt
grunt --force reporting

Problem with making Capistrano run the shell tasks (nodejs deploying)

I am using capistrano to deploy a node.js application, and have a
problem with setting the shell tasks.
For instance, thought I have npm installed this fails:
run "npm install"
npm not found
and when I use
run "/opt/nvm/'cat /opt/nvm/alias/default'/bin/npm install"
the error is node not found
The deploy is managed by a special user for deploy.
Could you please tell what might cause this problem and how to solve it?
Using NVM and Capistrano is working for me by running the command through bash and sourcing the nvm.sh file first.
My NVM is installed in /opt/nvm, so the npm install task could look something like this:
namespace :npm do
desc 'Install the current npm environment.'
task :install do
invoke_command "bash -c '. /opt/nvm/nvm.sh && cd #{current_path} && npm install'", :via => run_method
end
end
So no need of manually setting the path to the binaries by reading the alias file from NVM.
Sounds like the npm/node executables are not on the $PATH for the remote user that is executing the Capistrano script.
You should double check which user Capistrano is running as and what the $PATH is (and correcting as required)
I ended up adding this to my Capfile
set :default_environment, {
'PATH' => "$PATH:/usr/local/ruby/bin/:/home/ubuntu/.nvm/v0.10.21/bin"
}
In the meantime (more than a year back tho) I've created a Capistrano extension for easy nvm usage: https://github.com/koenpunt/capistrano-nvm
The extension will map node and npm by default, but you can add any executable that needs nvm to run to it (eg. grunt).
A basic setup would work by adding the following to your deploy.rb:
require 'capistrano/nvm'
set :nvm_type, :user # or :system, depends on your nvm setup
set :nvm_node, 'v0.10.21'
set :nvm_map_bins, %w{node npm}
I was able to affect node version changes by adding lines like the following to my capistrano deploy scripts:
execute :'. ~/.nvm/nvm.sh && nvm use vOLDER_VERSION && nvm alias default vOLDER_VERSION'
execute :npm, 'install', '--silent --no-progress'
execute :npm, 'run', 'build'
execute :'. ~/.nvm/nvm.sh && nvm use stable && nvm alias default stable'
Where vOLDER_VERSION is the version of choice.
The way this works is it sources nvm, sets it to use the specified version, and sets that version as default. It then reverts those changes after the npm steps have been run. This way other parts of the deploy or other deploys still get to use the latest version.
If you don't care about other deploys you could just run that step once for your deployer user:
su deployerUser
nvm use vOLDER_VERSION
nvm alias default vOLDER_VERSION

Resources