azure-devopsazure-pipelines

How can I inject Azure DevOps pipeline run number in a build artifact file?


I would like to have the Azure Devops pipeline build identifier (in red below) displayed in my deployed Angular app. Any suggestion on how can I do it, please?


Solution

  • You need to use $(Build.BuildNumber) variable to get this value. And now it depends what you have already in your angular application.

    For instance you can set this value in environment.ts file

    // environment.ts environment variables
    export const environment = {
      production: false,
      APIEndpoint: 'https://dev.endpoint.com'
      buildNumber: '#{Build.BuildNumber}#`
    };
    

    Via Token replace extension

    - task: qetza.replacetokens.replacetokens-task.replacetokens@3
      displayName: 'Replace tokens'
      inputs:
        targetFiles: |
          **/environment.ts
    

    You need to run this step before you compile angular app so the value reach your config.