Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Jenkins build batch命令中在Windows服务器上使用angular cli_Windows_Batch File_Jenkins_Path_Angular Cli - Fatal编程技术网

如何在Jenkins build batch命令中在Windows服务器上使用angular cli

如何在Jenkins build batch命令中在Windows服务器上使用angular cli,windows,batch-file,jenkins,path,angular-cli,Windows,Batch File,Jenkins,Path,Angular Cli,在安装Jenkins之前,我运行了以下命令: npm安装-g@angular/cli 但我在项目的package.json的devdependences中也有以下内容: “@angular/cli”:“1.0.0-beta.32.3” 运行Jenkins构建时,我在日志中看到以下消息: “ng”不被识别为内部或外部命令、可操作程序或批处理文件 ======================================= 以下是Jenkins中的Windows批处理命令: cmd/c调用npm

在安装Jenkins之前,我运行了以下命令: npm安装-g@angular/cli

但我在项目的package.json的devdependences中也有以下内容:

“@angular/cli”:“1.0.0-beta.32.3”


运行Jenkins构建时,我在日志中看到以下消息:

“ng”不被识别为内部或外部命令、可操作程序或批处理文件

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

以下是Jenkins中的Windows批处理命令:

cmd/c调用npm安装

设置路径=%WORKSPACE%\node\u modules\@angular\cli\bin;%路径%

echo%路径%

ng构建-产品

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

下面是Jenkins的更多日志输出:

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

“ng”未被识别为内部或外部命令, 可操作的程序或批处理文件

C:\ProgramFiles(x86)\Jenkins\workspace\UiUnitTests>exit 9009 生成步骤“执行Windows批处理命令”将生成标记为失败


但是,当我仅从命令行(而不是在Jenkins作业中)运行此命令时,效果很好:

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

您的全局Angular CLI版本(1.0.0-rc.1)高于本地版本 版本(1.0.0-beta.32.3)。使用本地CLI版本。 要禁用此警告,请使用“ng set--global warnings.versionMismatch=false”。 哈希:7853ecb5a81a25eadbeb 时间:61317毫秒 块{0}polyfills.7aaf5284cd5921eea40b.bundle.js(polyfills)278 kB{4}[首字母][呈现] chunk{1}main.3380f71d3e71966ea27.bundle.js(main)371kb{3}[首字母][呈现] chunk{2}styles.9DB1BAFFC989B37DB97.bundle.css(样式)69字节{4}[首字母][呈现] chunk{3}vendor.24574fc8320129058fac.bundle.js(vendor)2.18MB[首字母][呈现] chunk{4}inline.d1f5b52100bed2568d44.bundle.js(inline)0字节[输入][呈现]

C:\ProgramFiles(x86)\Jenkins\workspace\UiUnitTests>

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

最后但并非最不重要的一点是,这里是来自echo%PATH%

C:\Program Files(x86)\Jenkins\workspace\UiUnitTests>echo C:\Program Files(x86)\Jenkins\workspace\UiUnitTests\node\U 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:\ProgramFiles\nodejs\;C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps
C:\ProgramFiles(x86)\Jenkins\workspace\UiUnitTests\node\U 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:\ProgramFiles\nodejs\;C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps不全局安装CLI

为回购运行
npm install
,需要运行
ng
命令时,请使用以下命令:

node_modules/.bin/ng [command goes here]
这将节省安装时间,并确保本地版本和全局版本之间没有差异


附加说明:将应用程序更新至最新版本的CLI

尝试
npm run ng build
。唯一的问题是它忽略了任何其他参数,如
--prod
--test
生成后

以下是我在Jenkins成功运行angular build时使用的命令。最后一个命令是通过设置路径变量以脏方式执行的。我不知道是否有更干净的方法。这会正确执行命令,而不会遗漏任何内容

@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

您不需要直接运行ng。如果您使用npm脚本,将为您执行正确的ng命令。例如,您可以运行“npm run build--prod”为prod.works创建dist文件夹,非常好,谢谢!全局安装CLI不会有什么坏处,但它不是解决方案。@SebastianBallarati Jenkins不允许安装Angular CLI Globallyn不会将此作为答案,但对我来说,在运行ng build后,放置“call ng build--prod”会阻止它退出脚本。