Lineman spec-ci in jenkins - node.js

I have installed nodejs, npm, lineman, jenkins, and phantomjs on red hat.
I am trying to run a jenkins job that just runs lineman spec-ci to run my test-em tests. When I run this command as the jenkins user on the terminal, it runs. Unfortunately, when I run this command as a job in jenkins, it fails:
node: error while loading shared libraries: libhttp_parser.so.2: cannot open shared object file: No such file or directory
This error comes up even if I try to run npm install with the jenkins job.
The jenkins service is running under the user jenkins and if I run whoami during the jenkins build it outputs jenkins.
Any idea why I can run npm and lineman commands as the jenkins user but it fails when run as a job?

I ended up running printenv and found a variable associated with libraries. I added that variable to jenkins -> configure -> global properties.

Related

Issue regarding building a react app on Jenkins

I'm new to Jenkins and am trying to run the default react app as a free style project. Installed Jenkins as a docker image....The commands given are :
npm install
npm run build
Upon building the job, it shows execute shell marked an error in the build.
Upon further inspection, both the commands seem to be running
What could be the problem ?
I have added nodejs in the global configs....still no result...

Jenkins console execute shell running as root user instead of jenkins user

my jenkins test job console execute shell look like this;
#!/bin/bash
echo $(id)
npm -v
when I build this job the console output shown as;
uid=497(jenkins) gid=495(jenkins) groups=495(jenkins)
3.10.10
when I ssh into jenkins ec2 machine and then switch to jenkins user and run the command npm -v I got the different version of npm.
I suspect jenkins console execute shell run as root user shell where it picked up the npm version of root user.
when I run whoami and which npm I got the results on jenkins console as jenkins and /usr/bin/npm respectively, but while on jenkins ec2 instance when I run these commands on jenkins user shell I got the results as jenkins and ~/.nvm/versions/node/v8.10.0/bin/npm. please assist me to understand why I got two different results
Please assist. I appreciate your time

Jenkins and NodeJS

So I have a MEAN application up and running and Im looking into a continuous integration solution. I have successfully gotten Jenkins up and running with web hooks that grab my project from a bitbucket repo when a merge happens to master.
Right now I do not have any tests so Jenkins just runs some shell commands that 'deploys' the server. Which is great. My goal would be to have this run tests and fail a deploy if they fail.
So my problem is that the build never completes. My goal would be to when it completes it will keep the server running or deploy it and keep it running.
Here are the shell commands I run one the build is kicked off.
npm install
npm install bower
bower install
npm install grunt-cli
grunt prod
node server
And it successfully runs the server and such but it just hangs up after the node server command is executed
How do I make it so Jenkins sees this as successful and then deploys it? I have crawled the internet with no much luck.
EDIT:
So looking at some docs and such. I would need to configure my tests to run when the build gets ran. If there are not tests then it passes (by default)... So what I need is when that happens, jenkins needs to run a deploy script. After looking around in jenkins I am still unable to figure out how to do so.
EDIT #2
So moving those shell script out of the build allows it to finish and is 'successful' since no tests are present. I see that jenkins keeps the project in a workspace directory. Is there a way to get jenkins to deploy from there or some kind of other application to deploy that build in that workspace?
Thanks
So what I ended up doing was something simple but im not sure if its best practice..
Jenkins has the webhook to my bitbucket repo and watches for pulls into master. This then kicks off my jenkins build which it runs
npm install bower
bower install
npm install grunt-cli
grunt prod
which builds the project. Then I installed nodemon which watches the last "successful build" folder run the server from there. When it gets refreshed the server restarts. This seems to run pretty smoothly so far.

Running protractor from Jenkins

I am trying to run protractor on windows from the command line.
If I directly type the command:
webdriver-manager start
It works great.
However, from within jenkins, it keeps throwing:
'webdriver-manager' is not recognized as an internal or external command,
operable program or batch file.
My env vars seems ok, since the java and npm works fine from Jenkins.
Any idea?
As it turned out I simply forgot putting the C:\Users\USERNAME\AppData\Roaming\npm folder on the System variables and only configured it as my user path.
See elgalu's answer for your next problem though...
Install Protractor globally in the Jenkins machine, for this you may need to ssh into the Jenkins machine that run the tests:
ssh your-jenkins-server
npm -g install protractor
# update webdriver in the Jenkins machine
webdriver-manager update
# test it works
webdriver-manager start
Once you have that setup and running your next problem will probably be running Protractor headless unless your Jenkins machine has a display available and an installed windows manager like Ubuntu Desktop.

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.

Resources