I'm working on updating the environment variables in my React application using the Azure DevOps Release pipeline. While I've successfully replaced them in the CI build pipeline, I now need to extend this to support multiple environments in the Release pipeline.
Initially, I tried using .env files for variable management, but the Release pipeline didn't replace them from the build artifact. As a workaround, I created an env.js file to store the variables and attempted to replace them in the bundle.js file. However, I'm still struggling to replace the production variables with the values from the variable group in the Release pipeline.
As this didn't work, I tried using Bash script with sed commands.
I'm still getting this error. Could someone please help.









Update
Based on the further discussions, to configure the
ReplaceTokentask to replace the variables' names in theenv.jsfile with their respective values, we need to either define the variable value directly in the release pipeline or link a variable group where the variables are restored.At the same time, we need to make sure the target
env.jsfile is downloaded as an artifact, so that theReplaceTokentask is able to find and process it.In your screenshot, the
env.jsfile should be downloaded in the folder or the sub folder of$(System.DefaultWorkingDirectory)/_Trusana-UI-POC/drop/patient/for theReplaceTokentask to search for. For this, I used the commands below in aBashtask running on theubuntu-latestagent to confirm if the target file was downloaded under path$(System.DefaultWorkingDirectory)/_Trusana-UI-POC/drop/patient/and check the file contents after value replacement.From the screenshots that you shared, it seemed that you would replace the variables' names in the
env.jsfile with their values; however, in the release pipeline, you were targeting another filebundles.js.Please modify your pipeline to target the correct file where the pipeline variables were included.
env.js