I want to reference Azure CI Build.BuildNumber variable in my Angular app, but need a way to inject the build number into the environment file.
I have tried referencing the Azure environment variables but these are not replaced automatically on build.
2
Answers
You can do this with FileTransform
Create a file, variables.json
Import into your environment file/s
In your pipeline YML file:
I would recommend to use replaceToken task https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens to do the magic.
Create environment.ts file with conten.
How this works?
Pipeline variables that you have defined inside variables section will pick up buildNumber as pipeline variables. Now in replaceToken task, it will check for target file that is in our case environment.ts file and token prefix/suffix that in our case defined as ${}. When in replacetoken task, it will replace all variables that are encapsulated inside ${} prefix/suffix that is ${buildNumber} in our case. A similar case is also discussed here Best way to change a docker image tag in a azure pipeline with kubernetes