0

I am new to Angular and deployment in general.

I use Google Build and Google Run to build and deploy an Angular app. I've set up a trigger for continuous development with a Cloud Build configuration file (yaml). When I push my code to the GitHub repo the build activates.

In the Angular app I use environment variables using the environments directory and the environment.ts and environment.prod.ts files. I believe this is the standard way to use environment variables in Angular.

Of course, for security reasons, I don't push the environment files to the GitHub repo. So during the build I get the error 'cannot find module 'environments'. What is the best way in my case to add the environment variables to the build?

I've read that a possible solution is to add an extra 'environment.template.ts' file to the environments directory that uses placeholder values that you push to the GitHub repo. Then when using the ng build command, you can pass environment variables using the --configuration flag and specify the corresponding environment file: for example production build: ng build --configuration=production. But I can't seem to get the last step right.

How can I add environment variables step by step?

halfer
  • 19,824
  • 17
  • 99
  • 186
MariaJ
  • 11
  • 2

1 Answers1

-1

You can use Github secrets to store your environment variables. They can be accessed during the build.

Here is a good tutorial on the same: Github Secrets

Ajay Managaon
  • 450
  • 2
  • 9