Post shell script and complete the build - node.js

I am building and running node.js application through Jenkins.
I want to build and install all npm dependencies before starting the node.js.
and then when everything succeeded I want to run "npm start" without stuck the building status (because when I am doing npm start and starting the node.js express server, the console is waiting)
So I have this build shell script:
sudo npm install
npm start
And also I tried using a post shell script plugin for Jenkins and use it only for the npm start, but the same thing happened to me, and the build is just waiting...
I hope that you are able to understand me :)

I haven't needed to try something like this before, but you may be able to use a command such as nohup to allow the process to run in the background, for example: nohup npm start &. More info on the nohup command is available here

Related

npm run client & npm run server not running properly (won't run at the same time)

In the image you can see the scripts I am using, and on the left side is the folders hierarchy.
According to the defined script when I am running npm run watch, it should run server script and client script as well. But it's only running one script server. It never actually runs the client script.
Same thing happens if I put it like npm run client & npm run server in watch script. It runs only client script and never reaches server script.
One more: If I run npm install it doesn't install as defined in the script. Throws error EISDIR (error shown in image).
Please explain why is this happening and how I can fix this.
Thank you
there is a npm package called concurrently, you can install it as dev dependency and use it to run your watch script.
first install concurrently: "npm isntall concurrently --save"
then on your script: "watch": "concurrently "npm run server" "npm run client""
you can now run both server and client from one script.
source: https://www.npmjs.com/package/concurrently
Try running this script:
"watch":"npm-run-all --parallel server client"

How to run "npm run start" from release pipeline Azure DevOps to start production build in NUXTJS?

I want to create CI/CD for my nuxt application to deploy it on windows server. I have done all the things like copying files, npm install, npm run build. But the last step is to start the server by npm run start command and after running this command nuxt will show some related information like port no. etc and the command remains in the executable form (non-terminated command).
So when I run it from my pipeline the task is not terminating because of it.
https://nuxtjs.org/docs/get-started/commands#production-deployment
I had tried different little hacks like
Created batch file and run it as Power-shell command from start-process command
Open new cmd window to execute npm run start and close the previous one from this command "start cmd /k echo npm run start"
I use pm2 (it's free, https://pm2.keymetrics.io/) to daemonize nuxt on production servers. It works very well with nuxt and it respawns the process if for some reason crashes. That way you will exec a command on startup that will launch nuxt as a daemon in the background, but the command will terminate... that may solve your issue I think.

npm run doesn't work after install git for windows

I installed git for windows. Since then I can't run any electron project. Before the git installation it worked perfectly.
Now I have this error in the terminal on Visual Studio Code. How do I fix this?
Lifecycle scripts included in sample_gym_app:
start
electron .
PS E:\projects\electron test\gymapp> npm run
Scripts available in sample_gym_app via `npm run-script`:
pack
build --dir
I suspect you may have left out one of your npm parameters.
Try npm run start
The npm run command expects to receive the name of a script to run, oftentimes start.
If this answer is correct and works for you, consider doing some further reading on npm commands. See https://www.sitepoint.com/beginners-guide-node-package-manager/ for example.

How to run npm start via Jenkins to start application

executing shell
npm start &
wont work. Jenkins jobs either runs endless or npm does not start right.
What would be the proper way especially when u need to start multiple nodejs servers.
Is there a way over the jenkins nodejs plugin, via grunt or install a linux service running npm start ?
I also came across the same issue and figured out a way to do it. The command setsid helped me.
setsid npm start >/dev/null 2>&1 < /dev/null &

Jenkins script quitting prematurely when using npm install on Windows

In my Jenkins job I want to build a JavaScript app using Grunt. The Jenkins build scripts creates a build directory (if it doesn't already exist), changes to that directory and runs:
npm install grunt
npm install grunt-zip
grunt --gruntfile=[something]
(Of course grunt-cli is installed globally.) When I build the job, the first statement causes Grunt and dependencies to be pulled down as expected. However, the job then terminates successfully:
Archiving artifacts
No emails were triggered.
Finished: SUCCESS
The second npm install is not run. Any idea why the script is terminating after running npm install instead of continuing to the subsequent statements?
So it turns out that npm is a batch file, not an executable, so it needs to be invoked using call from the Jenkins script:
call npm install grunt
i would recommend not using the local grunt / nodejs install, but instead getting jenkins to do this for you!
it's much easier and means there's less coupling to system specific installs and variables.
steps:
a) use nodejs jenkins plugin + get it to install nodejs on machine/grunt-cli -> Jenkins integration with Grunt
b) populate your package.json with any nodejs dependances required, eg grunt/grunt-zip etc
c) when running grunt just do a "npm update" before "grunt" command
that way your not doing explicit npm install, it's all configured from your package.json, and your build scripts will be less brittle, and your developers can use the same steps as the build server, eg "npm update;grunt" locally same as build server
For future googlers:
use command chaining for this.
This works:
npm install && npm install install grunt-zip
This wont work:
npm install
npm install grunt-zip

Resources