I want to replace some text in a file after Jenkins does its build step.
I have the code below in my post build step.
powershell.exe -Command(Get-Content "./PublishedWebsites/app.config") |
Foreach-Object {$_.replace({{MyDummValue}}, "${env.BUILD_NUMBER}")} |
Set-Content "./PublishedWebsites/app.config"
The first part works (Get-Content "./PublishedWebsites/app.config") up until the pipe ("|").
After the pipe it throws an error that Foreach-Object is not recognized by an internal or external command.
I am thinking it has something to do with the escape sequence and the syntax. So I have tried this as well
"""powershell.exe -Command(Get-Content "./PublishedWebsites/app.config") |
Foreach-Object {$_.replace({{MyDummValue}}, "${env.BUILD_NUMBER}")} |
Set-Content "./PublishedWebsites/app.config"""
Then for some reason jenkins is trying to evaluate the $_.replace({{MyDummValue}} before the post build step is even reached and gives me the error of 'Cannot get property replace on null object'
So I am at a loss. All I want to do is on a post build step, rename a value in a file with the Build Number.