Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps Update Variable Inside Code Before Deploy

Is it possible for Azure DevOps to update part of my code when release kicks in?

For example, I have a setting file inside my react app. This setting file has export const ISPROD = false in it. I need Azure DevOps to change this false value to true before it builds the react app and deploys it. Is that possible?

Note: My Server build is Linux.

like image 873
Extelliqent Avatar asked Oct 25 '19 16:10

Extelliqent


Video Answer


1 Answers

You could update your code in your javascript files using the "Replace Tokens" task e.g.

- task: replacetokens@3
    inputs:
      targetFiles: "yourJavascriptFile.js"
      encoding: "auto"
      writeBOM: true
      verbosity: "detailed"
      actionOnMissing: "warn"
      keepToken: false
      tokenPrefix: "#{"
      tokenSuffix: "}#"
    displayName: Perform variable substitution in javascript file file

You'd add this task before the task you use to build your application.

In your javascript file you would write the variables to be replaced as e.g.

export const ISPROD = #{IS_PROD}#

This task when run would then replace "#{IS_PROD}#" with your Azure Devops variable named "IS_PROD" with it's value set as true.

like image 172
Ben Smith Avatar answered Sep 20 '22 22:09

Ben Smith