I am not sure if Octopus Deploy is actually to blame here, but I want to record this for anybody else encountering this same issue
We have a powershell script template the contained the following line of code:
$applicationVersion = $( $OctopusParameters[‘Octopus.Release.Number’] -Replace “(.)-(.)”, "$1"
-Replace ‘.’, ‘_’ )
Prior to 3.4.0, it worked fine in one of our older deployment servers (Windows 2008 R2, PowerShell v2), no problems. After upgrading to 3.4.0 where nothing else had changed in the environment or deployment scripts, the following error started occurring:
Unexpected token ‘` -Replace’ in expression or statement.
August 25th 2016 12:27:45Error
At C:\Deployments\Octopus\Work\20160825002742-73\Script.ps1:2 char:109
August 25th 2016 12:27:45Error
- $applicationVersion = $( $OctopusParameters[‘Octopus.Release.Number’] -Replac
August 25th 2016 12:27:45Error
e “(.)-(.)”, "$1"
-Replace <<<< ‘.’, ‘_’ )
August 25th 2016 12:27:45Error- CategoryInfo : ParserError: (` -Replace:String) [], ParentConta
August 25th 2016 12:27:45Error
insErrorRecordException
August 25th 2016 12:27:45Error - FullyQualifiedErrorId : UnexpectedToken
- CategoryInfo : ParserError: (` -Replace:String) [], ParentConta
We found that upgrading from Powershell v2 to Powershell v3 solved the issue.
We are not sure if Octopus has any impact on the powershell scripts, but it seems suspious that the only change to the server was a tentacle upgrade to 3.4.0 and then the script started failing.
Is it possible that 3.4.0 is dependent on Powershell v3 or higher, where v3.4.0-beta002 was not?
Was Octopus always dependent on Powershell v3, but for some reason we’ve managed to get away with it up until this release?
If anybody encounters their powershell scripts suddenly failing after upgrading to v3.4.0, upgrading to Powershell v3.0 solved the issue for me.