Search code examples
jenkinsnpmterminalbackgroundnohup

Jenkins freezes as the npm command does not return to terminal


Jenkins remote execute shell for Linux has the below command:

npm run develop

However, this command does not return to the terminal as below:

+ npm run develop

> [email protected] develop
> strapi develop


 Project information

[90m┌────────────────────[39m[90m┬──────────────────────────────────────────────────┐[39m
[90m│[39m Time               [90m│[39m Tue Oct 04 2022 10:02:58 GMT+0000 (Coordinated … [90m│[39m
[90m│[39m Launched in        [90m│[39m 1201 ms                                          [90m│[39m
[90m│[39m Environment        [90m│[39m development                                      [90m│[39m
[90m│[39m Process PID        [90m│[39m 422222                                           [90m│[39m
[90m│[39m Version            [90m│[39m 4.2.3 (node v16.17.0)                            [90m│[39m
[90m│[39m Edition            [90m│[39m Community                                        [90m│[39m
[90m└────────────────────[39m[90m┴──────────────────────────────────────────────────┘[39m

 Actions available

Welcome back!
To manage your project 🚀, go to the administration panel at:
http://localhost:1337/admin

To access the server ⚡️, go to:
http://localhost:1337

I can put it in background like below:

nohup npm run develop &

However, I need help determining if nohup npm run develop & command was successful or not.

nohup npm run develop > /dev/null 2>&1 &

This command also does not work.

Upon suggestion I tried the below:

#echo "nohup npm run develop &"
#nohup npm run develop &
#npm run develop  > /dev/null 2>&1 &
#BUILD_ID=dontKillMe nohup npm run develop &
export BUILD_ID=dontKillMe
export JENKINS_SERVER_COOKIE=dontKillMe
nohup npm run develop &

I tried unsuccessfully those that are commented with # as well

The process starts and then dies away after sometime.

Below is the output:

+ pwd
/etc/jenkins_tmp/workspace/SGGS_QA_API
+ export BUILD_ID=dontKillMe
+ BUILD_ID=dontKillMe
+ export JENKINS_SERVER_COOKIE=dontKillMe
+ JENKINS_SERVER_COOKIE=dontKillMe
+ '[' 0 -eq 0 ']'
+ echo 'npm run develop was successful. Copying ...'
npm run develop was successful. Copying ...
+ nohup npm run develop

> [email protected] develop
> strapi develop


 Project information

[90m┌────────────────────[39m[90m┬──────────────────────────────────────────────────┐[39m
[90m│[39m Time               [90m│[39m Tue Oct 04 2022 12:17:19 GMT+0000 (Coordinated … [90m│[39m
[90m│[39m Launched in        [90m│[39m 808 ms                                           [90m│[39m
[90m│[39m Environment        [90m│[39m development                                      [90m│[39m
[90m│[39m Process PID        [90m│[39m 424441                                           [90m│[39m
[90m│[39m Version            [90m│[39m 4.2.3 (node v16.17.0)                            [90m│[39m
[90m│[39m Edition            [90m│[39m Community                                        [90m│[39m
[90m└────────────────────[39m[90m┴──────────────────────────────────────────────────┘[39m

 Actions available

Welcome back!
To manage your project 🚀, go to the administration panel at:
http://localhost:1337/admin

To access the server ⚡️, go to:
http://localhost:1337

[2022-10-04 12:17:23.707] [32mhttp[39m: POST /admin/login (110 ms) 200
[2022-10-04 12:17:23.895] [32mhttp[39m: GET /admin/7814.ec45b22f.chunk.js (7 ms) 200
[2022-10-04 12:17:24.101] [32mhttp[39m: GET /admin/1362.b73aabfc.chunk.js (1 ms) 200
[2022-10-04 12:17:24.109] [32mhttp[39m: GET /admin/Admin-authenticatedApp.7216e34f.chunk.js (1 ms) 200
[2022-10-04 12:17:25.520] [32mhttp[39m: GET /admin/information (27 ms) 200
[2022-10-04 12:17:25.539] [32mhttp[39m: GET /admin/users/me (39 ms) 200
[2022-10-04 12:17:25.544] [32mhttp[39m: GET /admin/users/me/permissions (46 ms) 200
[2022-10-04 12:17:25.713] [32mhttp[39m: GET /i18n/locales (14 ms) 200
[2022-10-04 12:17:25.920] [32mhttp[39m: GET /admin/Admin_homePage.254acc19.chunk.js (1 ms) 200
[2022-10-04 12:17:26.144] [32mhttp[39m: GET /content-manager/components (13 ms) 200
[2022-10-04 12:17:26.159] [32mhttp[39m: GET /content-manager/content-types (25 ms) 200
Process leaked file descriptors. See https://www.jenkins.io/redirect/troubleshooting/process-leaked-file-descriptors for more information
Finished: SUCCESS

Can you please suggest?


Solution

  • The only solution that worked in jenkins for npm run develop was nohup npm run develop >> /var/www/logs/strapi.log 2>&1 &