Question: 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.

Answer: 
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](https://i.stack.imgur.com/5DCcq.png)
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!