15
votes

before installing Jenkins I ran this: npm install -g @angular/cli

but I also have this in devDependencies in the package.json for the project:

"@angular/cli": "1.0.0-beta.32.3",


when running a Jenkins build, I get this message in the log:

'ng' is not recognized as an internal or external command, operable program or batch file.

=======================================

Here is the Windows batch command in Jenkins:

cmd /c call npm install

set Path=%WORKSPACE%\node_modules\@angular\cli\bin;%PATH%

echo %PATH%

ng build -prod

========================================

here is a little more log output from Jenkins:

C:\Program Files (x86)\Jenkins\workspace\UiUnitTests>ng build -prod

'ng' is not recognized as an internal or external command, operable program or batch file.

C:\Program Files (x86)\Jenkins\workspace\UiUnitTests>exit 9009 Build step 'Execute Windows batch command' marked build as failure


but when I run this just from the command line (not in a Jenkins job), this works fine:

C:\Program Files (x86)\Jenkins\workspace\UiUnitTests>ng build -prod

Your global Angular CLI version (1.0.0-rc.1) is greater than your local

version (1.0.0-beta.32.3). The local Angular CLI version is used.

To disable this warning use "ng set --global warnings.versionMismatch=false". Hash: 7853ecb5a81a25eadbeb Time: 61317ms chunk {0} polyfills.7aaf5284cd5921eea40b.bundle.js (polyfills) 278 kB {4} [initial] [rendered] chunk {1} main.3380f71d3e71966aea27.bundle.js (main) 371 kB {3} [initial] [rendered] chunk {2} styles.9db1bafdfc989b37db97.bundle.css (styles) 69 bytes {4} [initial] [rendered] chunk {3} vendor.24574fc8320129058fac.bundle.js (vendor) 2.18 MB [initial] [rendered] chunk {4} inline.d1f5b52100bed2568d44.bundle.js (inline) 0 bytes [entry] [rendered]

C:\Program Files (x86)\Jenkins\workspace\UiUnitTests>

================================================

last but not least, here is the Jenkins log output from echo %PATH%

C:\Program Files (x86)\Jenkins\workspace\UiUnitTests>echo C:\Program Files (x86)\Jenkins\workspace\UiUnitTests\node_modules\@angular\cli\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Amazon\cfn-bootstrap\;C:\Ruby23-x64\bin;C:\Program Files\nodejs\;C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps C:\Program Files (x86)\Jenkins\workspace\UiUnitTests\node_modules\@angular\cli\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Amazon\cfn-bootstrap\;C:\Ruby23-x64\bin;C:\Program Files\nodejs\;C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps

2
Not going to put this as an answer, but for me, putting 'call ng build --prod' stopped it quitting the script after running the ng build.HockeyJ

2 Answers

28
votes

Do not install the CLI globally.

Run the npm install for the repo and any time you need to run an ng command use this:

node_modules/.bin/ng [command goes here]

This will save on install time and ensure there are no differences between your local and global versions.

Additional commentary: Update your app to the latest version of the CLI

3
votes

Try npm run ng build. The only issue with this is it omits any other parameter like --prod or --test after build.

Following are the commands what i am using to run my angular build successfully from Jenkins.The last command is executed the dirty way by setting up the path variables. Don't know if there is a cleaner way to do this. This does execute the commands properly without omitting anything.

@echo on
cmd /c npm install -g @angular/cli@latest

echo yarn Install
cmd /c yarn

echo Build
set PATH=%PATH%;C:\Users\Administrator\AppData\Roaming\npm;C:\Users\Administrator\AppData\Roaming\npm\node_modules\@angular\cli\bin;
ng build --prod --aot=true