Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng is not recognised as an internal or external command. Jenkins + Angular CLI

I am trying to setup Jenkins for an Angular CLI project. I have installed node and Angular Cli on the Jenkins server under a specific user account. if I open a command prompt on the server an execute the following commands to verify they are installed properly, this is the result:

enter image description here

I have configured the project with Jenkins, and i created two build steps two execute two bat files.

One runs: npm install

and the second one runs: ng build --prod

Then I build Jenkins, it runs the npm install but it fails running ng build --prod because it says " 'ng' is not recognised as an internal or external command".

Am I doing something wrong? Is there another way to probably use the angular cli on the node_modules folder, So it does not need to use the angular cli installed on the server. It seems like Angular CLI is installed only for my user on the server but not for the user Jenkins use to build.

PS: I installed Angular CLI globally using:

npm i -g @angular/cli

like image 611
D.B Avatar asked Nov 15 '17 00:11

D.B


2 Answers

No need to install angular cli on server, just run

npm run ng -- build 

That will run the local version from your project devDependencies

This way you can pass any flag to your local cli npm run ng -- test, npm run ng -- lint, etc

You can pass additional flags to ng just like that
run ng -- build --prod

More details at https://docs.npmjs.com/cli/run-script

like image 119
angularrocks.com Avatar answered Oct 06 '22 18:10

angularrocks.com


Just for further clarification when someone searches for the same problem and finds this question (as I did):

If you want to use the --prod flag while running the build command, as asked in this question, you can use:

npm run ng -- build --prod

Important are the "--" between "ng" and "build" with spacing. This is due to the syntax of "npm run", more information can be found here: https://docs.npmjs.com/cli/run-script

This also solves the problem described in a comment below the accepted answer: "This is working but its excluding the additional parameters like --test when running the build"

like image 24
apexde Avatar answered Oct 06 '22 19:10

apexde