0

I am trying to build an angular project in Jenkins

Tried both

"build": "npm run ng build",

as well as

"build": "ng build"

but getting the same error. Could it be because of the way this project has been set up in jenkins ?

On my local machine, setting

"build": "npm run ng build"

works fine. But it fails on jenkins.

Jenkins log below -

12:54:27 > ******* build /home/jenkins/workspace/********
12:54:27 > npm run ng build
12:54:27 
12:54:27 
12:54:27 > ******* ng /home/jenkins/workspace/**********
12:54:27 > ng "build"
12:54:27 
12:54:27 sh: ng: command not found
12:54:27 npm ERR! code ELIFECYCLE
12:54:27 npm ERR! syscall spawn
12:54:27 npm ERR! file sh
12:54:27 npm ERR! errno ENOENT
12:54:27 npm ERR! ******* ng: `ng "build"`
12:54:27 npm ERR! spawn ENOENT
12:54:27 npm ERR! 
12:54:27 npm ERR! Failed at the ******** ng script.
12:54:27 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
12:54:27 npm WARN Local package.json exists, but node_modules missing, did you mean to install?
12:54:27 
12:54:27 npm ERR! A complete log of this run can be found in:
12:54:27 npm ERR!     /home/jenkins/.npm/_logs/2020-09-09T18_54_22_494Z-debug.log
12:54:27 npm ERR! code ELIFECYCLE
12:54:27 npm ERR! errno 1
12:54:27 npm ERR! ******* build: `npm run ng build`
12:54:27 npm ERR! Exit status 1
12:54:27 npm ERR! 
12:54:27 npm ERR! Failed at the ******** build script.
12:54:27 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
12:54:27 npm WARN Local package.json exists, but node_modules missing, did you mean to install?
12:54:27 
12:54:27 npm ERR! A complete log of this run can be found in:
12:54:27 npm ERR!     /home/jenkins/.npm/_logs/2020-09-09T18_54_22_527Z-debug.log
12:54:27 /tmp/jenkins4346657790254352101.sh: line 12: cd: 
/var/lib/jenkins/workspace/********/dist: No such file or directory
12:54:27 cp: cannot stat 
‘/var/lib/jenkins/workspace/******/dist/********’: No such file or directory
12:54:27 Build step 'Execute shell' marked build as failure
12:54:27 New run name is 'CZ BLD# 254796'
12:54:27 Notifying upstream projects of job completion
12:54:27 Finished: FAILURE
Jason Goemaat
  • 28,692
  • 15
  • 86
  • 113
Vivek Vermani
  • 1,934
  • 18
  • 45
  • 1
    try `npm run build` – Kardon63 Sep 09 '20 at 18:48
  • Thanks for the quick response. Just tried it but then it run into endless loop of "npm run build" command execution. – Vivek Vermani Sep 09 '20 at 18:51
  • 1
    Have you tried `npm install`? You shouldn't put 'npm run' in the same script as the script you are running. What 'npm run' does is execute that script. If the build script has 'npm run build', then typing 'npm run build' will execute that script, which will run 'npm run build' which will execute that script, which will run 'npm run build' which will execute that script. And on, and on. – Jason Goemaat Sep 09 '20 at 19:01
  • 1
    What about "./node_modules/.bin/ng build". If you get Error probably working directory isn't OK – MRsa Sep 09 '20 at 19:15
  • 1
    Thanks @MRsa , Yes node modules were not checked in."build" : "npm ci && npm run ng build" did the trick. Thanks everyone. Appreciate your help. – Vivek Vermani Sep 09 '20 at 21:12

1 Answers1

0

in pipeline add below, i hope this will solve the problem, i was facing the same issue while using jenkins pipeline to build my react application.

pipeline{
environment { 
        CI = 'false'
    }
#your complete pipeline stages and steps for npm and other commands

}
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 27 '21 at 20:58