最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular-cli build (ng build) on Teamcity - Stack Overflow

programmeradmin1浏览0评论

I hope someone has already done this. I am trying to set up a continuous build in teamcity for one my angular 2 project. After done some research and I have followed the steps as follows:

  1. Build Step1: installed the jonnyzzz.node plugin for the teamcity. (Now I can pick Node.js NPM from Runner type)
    npm commands: I added install command
  2. Build Step 2: Another Node.js NPM and npm commands: install -g angular-cli
    So far so good
  3. Now I wanted to build ng build as the third step and I am really stuck as I have no way to do this.

Any help would be appreciated.

Thank you.

I hope someone has already done this. I am trying to set up a continuous build in teamcity for one my angular 2 project. After done some research and I have followed the steps as follows:

  1. Build Step1: installed the jonnyzzz.node plugin for the teamcity. (Now I can pick Node.js NPM from Runner type)
    npm commands: I added install command
  2. Build Step 2: Another Node.js NPM and npm commands: install -g angular-cli
    So far so good
  3. Now I wanted to build ng build as the third step and I am really stuck as I have no way to do this.

Any help would be appreciated.

Thank you.

Share Improve this question edited Feb 20, 2017 at 11:14 Daniel Hilgarth 174k40 gold badges343 silver badges449 bronze badges asked Dec 1, 2016 at 21:12 RavimaranRavimaran 4411 gold badge3 silver badges10 bronze badges 1
  • I have resolved my own problem. I have modified the npm package.json and added ng build. – Ravimaran Commented Dec 1, 2016 at 21:59
Add a comment  | 

3 Answers 3

Reset to default 10

Rather than changing your package.json you can use the node.js NPM plugin and the run command:

run build

build it not a default command for NPM so you need the 'run build' which is mapped to ng build in default ng-cli package.json

"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
},

See image

In order to get ng build work from nodejs plugin for Team city, I have modified the package.json file. In start replace the value with "ng build". And from team city, npm build command will trigger the ng build command.

First start with the build agents where you can edit the buildAgent.properties file and define 3 environment variables. You should have the surrounding single quotes here or later on in your build definitions:

env.exec.node='C\:\\Program Files\\nodejs\\node.exe'
env.exec.npm='C\:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js'
env.exec.ng='%env.APPDATA%\\npm\\node_modules\\@angular\\cli\\bin\\ng'

The %env.APPDATA% is used here but some setups may be installed on the Program Files, in most cases the AppData will be the one to take.

Next you can define build steps for your project. Create these new build steps of type Powershell and set Script as Source Code. Inside the Script Source you can now enter:

Install Angular CLI

& %env.exec.node% %env.exec.npm% install -g @angular/cli

Install node_modules folder

& %env.exec.node% %env.exec.npm% install

Build and publish solution

& %env.exec.node% %env.exec.ng% build --environment '%env.build.environment%' --scripts-prepend-node-path

After this step production builds will create your dist folder which you can include into your Artifacts paths so you have access to it should you want to create seperate Deployment type build configurations

Some considerations to take into account here:

  • You could define the variables inside your however different paths may be used on the build agents, which would brake your builds
  • Make sure you have proper Clean-Up Rules in place, since node_modules folders can get big really fast

Hope it helps out someone!

发布评论

评论列表(0)

  1. 暂无评论