Issue regarding building a react app on Jenkins - node.js

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...

Related

How to install node js on gocd agent?

While running node js app on gocd build pipeline i am get make sure npm install can be run on this agent.
How to install node js on gocd server to run test.
make sure npm install can be run on this agent. &
How to install node js on gocd server to run test."
Both are completely two different things. You might have to spend little more time on understanding differences in responsibilities of GoCD server and Agent.
On a brief note you do not need to install nodejs on gocd server to run tests. All the tasks are run by "GoCD Agents". So you can go and manually install nodejs on GoCD agent (or) you can use nodejs docker container as agent which will have nodejs by default.

How to run Jest tests on Jenkins Server

I'm attempting to run my Jest Test during Jenkins deployment. If I ssh into the server, I can sudo into the Jenkins user and successfully run the tests from the workspace. However, I get an error when I attempt to build the project from the GUI. Here is my project setup:
I have installed the nodejs plugin, which in turn installs gulp, jest-cli and babel globally.
Then in build steps:
The test fails with this error:
TypeError: Cannot read property 'getResourceByPath' of null
at Loader.getDependenciesFromPath (/var/lib/jenkins/workspace/PHPStaging/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:570:39)
at /var/lib/jenkins/workspace/PHPStaging/node_modules/jest-cli/src/TestRunner.js:250:22
at process._tickCallback (node.js:368:9)
Running 6 test suites...
FAIL resources/__tests__/myTest.js
It appears that Node is having trouble requiring modules from the tests, but I'm not totally sure. Any help or direction would be appreciated.

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.

Lineman spec-ci in jenkins

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.

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

Resources