如何在Jenkins构建批处理命令中在Windows Server上使用angular cli

use*_*225 14 windows path batch-file jenkins angular-cli

在安装Jenkins之前我运行了这个: npm install -g @ angular/cli

但我也在package.json中的devDependencies中为项目提供了这个:

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


在运行Jenkins构建时,我在日志中收到此消息:

'ng'不被识别为内部或外部命令,可操作程序或批处理文件.

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

这是Jenkins中的Windows批处理命令:

cmd/c调用npm install

设置路径=%WORKSPACE%\node_modules\@angular\cli\bin;%PATH%

echo%PATH%

ng build -prod

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

这是Jenkins的更多日志输出:

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

'ng'不被识别为内部或外部命令,可操作程序或批处理文件.

C:\ Program Files(x86)\ Jenkins\workspace\UiUnitTests>退出9009构建步骤'执行Windows批处理命令'将构建标记为失败


但是当我从命令行运行时(不是在Jenkins工作中),这很好用:

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

您的全局Angular CLI版本(1.0.0-rc.1)大于您的本地版本

版本(1.0.0-beta.32.3).使用本地Angular CLI版本.

要禁用此警告,请使用"ng set --global warnings.versionMismatch = false".哈希:7853ecb5a81a25eadbeb时间: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] [rendering] chunk {4} inline.d1f5b52100bed2568d44.bundle.js(内联)0字节[entry] [render]

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

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

最后但并非最不重要的,这是来自echo%PATH%的Jenkins日志输出

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

Bro*_*cco 27

不要全局安装CLI.

运行npm installrepo,任何时候需要运行ng命令使用:

node_modules/.bin/ng [command goes here]
Run Code Online (Sandbox Code Playgroud)

这将节省安装时间并确保本地和全球版本之间没有差异.

其他评论:将您的应用程序更新到最新版本的CLI

  • 您不需要直接运行ng.如果使用npm脚本,将为您执行正确的ng命令.例如,您可以运行"npm run build - --prod"来为prod创建dist文件夹. (6认同)