71

Angluar CLI is asking the following question when I am trying to build and deploy my project using gitlab CI/CD:

> @angular/cli@8.0.0 postinstall /workspace/node_modules/@angular/cli
> node ./bin/postinstall/script.js

? Would you like to share anonymous usage data with the Angular Team at Google u
nder
Google’s Privacy Policy at https://policies.google.com/privacy? For more details
 and
how to change this setting, see http://angular.io/analytics. (y/N) 

Of course I cannot input anything in the CI/CD pipeline. How can I can prevent angular cli from asking this question?

Arman Fatahi
  • 2,635
  • 3
  • 24
  • 37

13 Answers13

61

I had the same problem: The new analytics feature of Angular CLI was blocking my CI: https://travis-ci.org/LVM-IT/lvo-logging-lib. Solution: set the environent variable NG_CLI_ANALYTICS equal to ci

export NG_CLI_ANALYTICS=ci

see: https://github.com/LVM-IT/lvo-logging-lib/blob/329d014aa34dea49522f036e8d0b3aa3f71e33e7/.travis.yml#L16

Link to ng-cli Analytics

Dirk Lammers
  • 756
  • 6
  • 8
  • 1
    You can add this link to your answer: https://github.com/angular/angular-cli/blob/master/docs/design/analytics.md – Arman Fatahi May 30 '19 at 02:50
  • 2
    Where do you set NG_CLI_ANALYTICS ? – Blunderchips Jun 10 '19 at 09:33
  • you can set it in your shell before runnung cli with export NG_CLI_ANALYTICS=ci. Here is an example for setting it on a Travis Build https://github.com/LVM-IT/lvo-logging-lib/blob/329d014aa34dea49522f036e8d0b3aa3f71e33e7/.travis.yml#L16 – Dirk Lammers Jun 10 '19 at 10:49
  • 1
    Done this. The env vars in Circle CI build logs saying: `Using environment variables from project settings and/or contexts CIRCLE_JOB=**REDACTED** NG_CLI_ANALYTICS=**REDACTED**`. Yet, the ng still requests for input – KhoPhi Jul 01 '19 at 11:22
  • @Rexford: so there is a Problem with your circle ci configuration or with circle ci itself. As demonstrated above it works on Travis CI. follow the link for a configuration example for travis: https://github.com/LVM-IT/lvo-logging-lib/blob/329d014aa34dea49522f036e8d0b3aa3f71e33e7/.travis.yml#L16 – Dirk Lammers Jul 02 '19 at 14:24
  • What if it pops up for me locally and I want to disable it completely, without making changes to my repository? – Ivan Yurchenko Mar 20 '20 at 09:45
  • Add `NG_CLI_ANALYTICS=false` to `/etc/environment` on Linux, to set it globally. – DJDaveMark Mar 07 '23 at 17:17
51

Add following property to angular.json file:

  "cli": {
    "analytics": false
  }
Palpatine1991
  • 750
  • 6
  • 13
  • WebStorm gives me a warning saying "Property 'analytics' is not allowed", with the quick fix being "Remove prohibited property 'analytics'" – Guilherme Taffarel Bergamin Sep 22 '22 at 13:54
  • Thank you! Not all of us want everything to be global and bound to a machine instead of a project (and some of us just use notepad)! This goes right at the top level inside the first paren set: https://angular.io/guide/workspace-config – Cris Mooney Feb 08 '23 at 22:42
26

I used the command,

ng analytics off

and the prompt was not shown again.

Reference: https://angular.io/analytics#disabling-usage-analytics

schoolcoder
  • 1,546
  • 3
  • 15
  • 31
  • 2
    This doesn't work cause running this command actually causes the question for me. – Chip Allen Mar 04 '20 at 20:16
  • 1
    Don't know why this answer get downvoted but it worked for me. – Tuyen Pham Apr 21 '20 at 15:37
  • 2
    upvoted. It would work for you have access in the environment(e.g local). You can use the answer if you want it to turn off globally. @ChipAllen I think you run the command inside your project. You can run it outside the angular projects to avoid prompting the question. – Kenneth Apr 30 '20 at 06:10
  • 2
    it worked for me. I wish I should have landed here earlier. – Praveen Kumar May 04 '20 at 06:35
  • 1
    upvoted, agreed with @kenneth, as per official document execute command outside the project. https://angular.io/analytics – Deva May 28 '20 at 06:19
  • This should have been the answer. – Saturn K Feb 04 '21 at 19:23
  • 3
    If you have @ChipAllen 's problem and if this doesn't work for you, and it keeps prompting, try using ```ng analytics disable --global true``` in newer angular versions. Source: [here](https://stackoverflow.com/questions/56355499/stop-angular-cli-asking-for-collecting-analytics-when-i-use-ng-build) – nico van vuuren Sep 21 '22 at 10:10
  • Running `ng analytics off` pops the answer, then after you answer it, it will set up `angular.json` like @Palpatine1991 said in his answer. – Guss Dec 01 '22 at 14:58
  • `ng analytics off -g` for short to disable everywhere, cheers! – Sean Kendle Mar 25 '23 at 22:31
10

To solve this, run the command appointing to /dev/null

sudo npm install -g @angular/cli > /dev/null
Liam
  • 27,717
  • 28
  • 128
  • 190
5

exporting the env variable didn't work for me... What did work was this

echo N | ng analytics off

it didn't ask again afterwards

adelmoradian
  • 312
  • 3
  • 3
5

NG_CLI_ANALYTICS="false" is the correct env variable value

see linked comment;

"export NG_CLI_ANALYTICS=off didn't work for me, but export NG_CLI_ANALYTICS="false" does"

https://github.com/angular/angular-cli/issues/16784#issuecomment-637693422

Koonts
  • 51
  • 1
  • 2
2

For circle CI, this worked for me:

- run:
    environment:
      NG_CLI_ANALYTICS: "ci"
    command: npm install
Dangular
  • 389
  • 1
  • 3
  • 15
2

I resolved this by adding the environment variable in my machine by running this PowerShell command with Admin privilege.

[Environment]::SetEnvironmentVariable("NG_CLI_ANALYTICS", "false", "Machine")

Basically, there are 2 approaches to fix this.

  1. Add analytics: false value in angular.json file which the prompt or ng analytics off command does automatically.
  2. For me approach 1 was not feasible as updating project's angular.json file was not acceptable therefore I preferred to set environment variable NG_CLI_ANALYTICS variable as false in my machine. This is the cleanest approach and wouldn't affect other's environment.
N. Raj
  • 319
  • 4
  • 14
2

You can use export NG_CLI_ANALYTICS="false" in bash,

or it is ARG NG_CLI_ANALYTICS="false" in Dockerfile.

Martin
  • 696
  • 6
  • 7
1

Script circle CI to disable it, if the analytics prompt blocking the CI

 - run:
      name: 'Set env'
      command: echo 'export NG_CLI_ANALYTICS=ci' >> $BASH_ENV
Wei Lun
  • 45
  • 2
  • 9
0

use this commond to off...##

ng analytics project off

it works....

0

For anyone in a rush, it may be worthwhile clarifying that when you run ng analytics off or ng analytics disable from the root of your Angular project, the Angular CLI will add, on your behalf, the following to your angular.json:

 "cli": {
    "analytics": false
  }

So, you get to choose: you either run the CLI command or you add it manually to your angular.json. However, if you decide to use the CLI command,

  1. verify that your angular.json was correctly updated and
  2. commit those changes.

Do not expect the Angular CLI command to work as part of a deployment script on a remote server.

licvdom
  • 76
  • 5
-2

En angular.json, agregar al final o inicio: "cli": { "analytics": false }

quedaria algo asi:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    ...
  },
  "defaultProject": "z",
  "cli": {
    "analytics": false
  }
}
FerNanDo
  • 9
  • 1