2

I'm trying to find a way to pass or "inject" to the build system of Angular for the version and build number to be taken from the user as input for our CI/CD pipeline.

Is there any way to do it without hard-coding the version number in the code/environment .ts files?

Eldar
  • 9,781
  • 2
  • 10
  • 35
Or Yaacov
  • 3,597
  • 5
  • 25
  • 49
  • 2
    You can create a separate file under assets. Write the version into that file after the build is completed through jenkins or whichever tool you use. Your code will then refer that file for the version. – Amit Chigadani Dec 15 '19 at 15:52
  • 1
    You can refer this [to insert build number](https://stackoverflow.com/questions/41733660/how-to-insert-a-build-number-or-timestamp-at-build-time-in-angularcli) – biff Dec 16 '19 at 04:20
  • 1
    Thank you guys. until that there will be an official solution, I implemented @AmitChigadani method just because it's the fastest one with minimum changes. you can write it as an answer – Or Yaacov Dec 16 '19 at 17:31

1 Answers1

1

Possible approach without using any environment files:

  1. Create a separate file under assets folder.
  2. Write the new version into that file after the build is completed through Jenkins or whichever tool you use. You can get the build version in Jenkins through its environment variable ${BUILD_NUMBER}

  3. Your code will then refer that file for the version.

Amit Chigadani
  • 28,482
  • 13
  • 80
  • 98