ng 不被识别为内部或外部命令.詹金斯 + Angular CLI [英] ng is not recognised as an internal or external command. Jenkins + Angular CLI

查看:25
本文介绍了ng 不被识别为内部或外部命令.詹金斯 + Angular CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 Angular CLI 项目设置 Jenkins.我已经在特定用户帐户下的 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:

我已经用 Jenkins 配置了项目,我创建了两个构建步骤,两个执行两个 bat 文件.

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

一次运行:npm install

One runs: npm install

第二个运行:ng build --prod

and the second one runs: ng build --prod

然后我构建 Jenkins,它运行 npm install 但它运行 ng build --prod 失败,因为它说'ng'不被识别为内部或外部命令".

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".

我做错了吗?有没有另一种方法可以在node_modules文件夹上使用angular cli,所以它不需要使用服务器上安装的angular cli.似乎 Angular CLI 只为我在服务器上的用户安装,而不是为 Jenkins 用来构建的用户安装.

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:我使用以下方法全局安装了 Angular CLI:

PS: I installed Angular CLI globally using:

npm i -g @angular/cli

npm i -g @angular/cli

推荐答案

无需在服务器上安装angular cli,直接运行

No need to install angular cli on server, just run

npm run ng -- build 

这将运行您项目中的本地版本devDependencies

That will run the local version from your project devDependencies

通过这种方式,您可以将任何标志传递给本地 cli npm run ng -- testnpm run ng -- lint

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

您可以像这样将其他标志传递给 ng
运行 ng -- build --prod

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

更多详情请见 https://docs.npmjs.com/cli/run-script

这篇关于ng 不被识别为内部或外部命令.詹金斯 + Angular CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆