Angular CLI VSO持续集成 [英] Angular CLI VSO Continuous Integration

查看:105
本文介绍了Angular CLI VSO持续集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去我已经为使用npm命令的Angular2项目设置了CI,但是最近我开始使用Angular-CLI来代替,而Angular-CLI则使用了"ng"命令.

当我尝试在Visual Studio Online中为我的项目设置CI时,我找不到执行'ng'命令的方法.

我尝试运行NPM命令(使用目录中的npm任务)来安装CLI; npm install -g angular-cli,之后我运行npm install.现在要运行"ng build",我尝试使用命令行工具运行(因为似乎没有允许我运行ng命令的工具),但是无法说ng不是可识别的命令./p>

关于使用VSO为Angular-CLI项目设置CI的任何建议吗?

谢谢

解决方案

如果要在任何构建代理(托管的代理和任何本地代理)上运行构建定义,则可以依赖的本地安装带有 npm 的angular-cli 没有 -g标志:

>npm install angular-cli

默认情况下,npm将在.\node_modules\.bin\

下安装'ng'

您的构建定义可以使用'npm install' 任务以在本地安装'ng',然后您可以通过命令行" 任务,因为您知道它的路径(例如$(Build.SourcesDirectory)\node_modules\.bin).

创建定义并使用'ng'

进行构建的构建定义示例:

  • 在本地安装"ng" cli工具:

  • 创建项目"helloworldproject":

  • 构建项目"helloworldproject":

==更新(通过"npm bin"以编程方式检索实际的二进制路径)==

要删除假定放置二进制文件并具有更灵活的构建定义的假设,可以使用以下命令以编程方式检索 npm 使用的实际二进制路径:

>npm bin

以下示例(这次是一个简短的PowerShell脚本)显示了如何创建"helloworldproject"并在其后进行构建:

记住:

  • 禁用PowerShell任务上的标准错误失败"选项,因为ng工具喜欢在其中写入内容,即使成功也可以.
  • 当然,在使用'ng'工具之前,您仍然需要如上所示的'npm install'任务.

I have set up CI for Angular2 projects in the past which use npm commands, however I recently started using Angular-CLI which uses 'ng' commands instead.

When I try to set up CI for my project in Visual Studio Online I can't find a way to execute 'ng' commands.

I have tried running NPM command (using npm task from the catalog) to install the CLI; npm install -g angular-cli, after that I run npm install. Now to run 'ng build' I have tried to run in using command line tool (since there doesn't appear to be a tool to allow me to run ng commands), however that fails saying that ng is not a recognised command.

Any suggestions on setting up CI for an Angular-CLI project using VSO?

Thanks

解决方案

If you want your build definition to run on any build agent (the Hosted one and any on premise agent), you could relying on local installation of angular-cli with npm, without the -g flag:

>npm install angular-cli

By default npm will install 'ng' under .\node_modules\.bin\

Your build definition could use the 'npm install' task to install locally 'ng', then you can invoke it by 'Command Line' task because you know the path to it (e.g. $(Build.SourcesDirectory)\node_modules\.bin).

Example of a build definition creating a new project and building it using 'ng':

  • install locally the 'ng' cli tool:

  • create the project 'helloworldproject':

  • build the project 'helloworldproject':

==Update (programmatically retrieve the actual binary path with 'npm bin')==

To remove the assumption where the binaries are placed and have a more resilient build definition, you could retrieve programmatically the actual binary path used by npm using the command:

>npm bin

The following example (this time a short PowerShell script) shows how to create the 'helloworldproject' and build it thereafter:

Remember:

  • to disable the option 'Fail on Standard Error' on the PowerShell task, as the ng tools likes to write stuff there even when it succeeds.
  • of course you still need the 'npm install' task as shown above before using the 'ng' tool.

这篇关于Angular CLI VSO持续集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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