1

I have an angular application only - no backend

I want to display my private branch name in my angular application (e.x. myName/myFeature)

I'm using Azure DevOps for deploy my app in the cloud

I searched the web for tutorials\guides but I think I'm missing something.

The best tutorial I've found is this: https://www.taithienbo.com/replacing-variables-in-an-angular-app-using-replace-token-extension/

But still it is not working, it is not displaying the correct branch name.

enter image description here

Code:

  • component.ts

    import {environment} from '../../../../environments/environment'; version: string = environment.version;

  • component.html

    {{version}}

  • environment.ts

    version: '#{Build.BuildNumber}#'

DevOps:

enter image description here

enter image description here

It is displaying the wrong branch name, the upper instead of the bottom:

enter image description here

assaf.gov
  • 517
  • 6
  • 19
  • 1
    Could you show us your code and build pipeline? If you followed this tuotrial I don't see why it wouldn't work. – J.Loscos Jul 13 '21 at 07:17
  • Better, but still not enough, please share with us your pipeline and logs for this task. – Krzysztof Madej Jul 13 '21 at 07:32
  • Sure, is it enough? – assaf.gov Jul 13 '21 at 07:53
  • I would use the build scripts (npm build) to generate the file - that way it works also if you build locally and not only on DevOps: https://stackoverflow.com/questions/42155115/how-to-include-git-revision-into-angular-cli-application – fredrik Jul 13 '21 at 09:09

1 Answers1

0

In the build config the setting you're looking for is here;enter image description here

Following that link you can find the documentation which (although for yaml pipelines) gives an example;

$(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)

For your purposes you'd just want

$(SourceBranchName)
Adam
  • 4,180
  • 2
  • 27
  • 31
  • You are suggesting to change the build the number to be the branch name. I want the build number to stay as it is and still to display the branch name in the application – assaf.gov Jul 15 '21 at 05:53
  • Understood. I was mostly working off the final image you posted. I'll post a new answer if I come up with something. – Adam Jul 15 '21 at 09:31