Reputation: 1856
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.
Upvotes: 6
Views: 4197
Reputation: 20230
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.
Upvotes: 5
Reputation: 532
If you want to make a custom solution following might help full to you
Upvotes: 2
Reputation: 26992
Since you're on linux you can just add the bash task or shell script task to your build and add an inline script or path to a script in your repo that does the setting update.
You'll need to take a look at the available environment variables in your pipeline that you can use in your script to access the working directory of your code.
You can optionally specify conditions under which the task runs. For example, I do something very similar when versioning our components for release, which are only done during builds triggered by a git tag.
Upvotes: 3
Reputation: 3840
Here's a free Visual Studio Marketplace Pipeline task that will do the trick: Replace Text in Source Files
This one will also work: RegexReplace Build Task
Upvotes: 2