首页 > 解决方案 > Is there a way to provide environment.prod.ts file in a Azure CI build pipeline while building an Angular App?

问题描述

I am looking for possible ways for providing the environment.prod.ts file into the Azure CI build pipeline, as we don't check-in those environment-specific (environment.prod.ts or environment.dev.ts) files into the repo.

Is there a specific YAML task for it? How to ensure that the Azure CI pipeline can get this file in order to build the Angular application.

Thanks in Advance!

标签: angularazureazure-devops

解决方案


You can use regular linux commands like echo to create a file dynamically.In this case, make sure your environments folder (src/environments) is not empty (even an empty readme.md file would work).

If it is empty then Azure CI might not create this directory while taking clone of repo.

After that, you can use echo command in your azure-pipelines script and it will look like below:-

# Node.js with Angular
# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '14.x'
  displayName: 'Install Node.js'

- script: |
   echo $DEV_ENVIRONMENT>src/environments/environment.ts
   echo $PROD_ENVIRONMENT>src/environments/environment.prod.ts
   npm install -g @angular/cli
   npm install
   ng build --prod
 displayName: 'npm install and build'

Check echo command under scripts.

I've stored contents of environment.ts and environment.prod.ts in DEV_ENVIRONMENT and PROD_ENVIRONMENT so that developer doesn't know what's inside the file.


推荐阅读