I'm trying to execute the following Powershell script during the Jenkins build process:
Write-Host ==================================================
Write-Host Setting Version to $env:Version BEGIN
(Get-Content .\MyFile.js) -replace '"Version"\s*:\s*".*"', '"Version" : "$env:Version"' | Out-File .\MyFile.js
Write-Host Setting Version to $env:Version COMPLETE
Write-Host ==================================================
The first and last instances of $env:Version get substituted correctly. I see the output
==================================================
Setting Version to 1.2.3.4 BEGIN
Setting Version to 1.2.3.4 COMPLETE
==================================================
But the second instance of $env:Version does not get replaced in MyFile.js. When I open up MyFile.js, I see the following:
"Version" : "$env:Version",
How can I pass this environment variable to the Get-Content command? Is it something about regular expressions (triggered by -replace) that is preventing the substitution from happening?