Post-Deploy Start Scheduled Task

I have a deployment that requires I replace a running scheduled task.
I created three tasks in my processes. Run a PowerShell Script, Deploy NuGet Package, Run a PowerShell Script.

Steps

  1. I have a simple script that calls “schtasks /End /TN $TaskName”
  2. I have the tentacle unpack the nuget package into the directory where the scheduled task was running from
  3. I have a simple script than calls “schtasks /Run /TN $TaskName”

I can’t seem to figure out why step 3 fails. If I copy and paste the script into a powershell on the machine it works fine. However in the deploy log on octopus deploy, its telling me:

ERROR: Invalid syntax.
Error    14:29:43
Type "SCHTASKS /?" for usage.
Fatal    14:29:43
PowerShell script returned a non-zero exit code: 1
Tentacle version 2.5.10.567

Here is what my step 3 script looks like

$taskName = $OctopusParameters['TaskName']

Write-Output "Starting $taskname..."

schtasks /Run /TN $taskName

The only difference between step 1 and step 3 is the /Run is /End and it works in Step 1.
Just to reiterate, if copy and paste that into a local powershell ( and predefine $taskName) it works fine.

Any Ideas?

I should also point out that I just tried the command in the script console and it worked there. I literally copied the working one from the script console into the third steps script to run box and it still fails.

Is there something special about the post deploy powershell?

Hi,

Thanks for getting in touch! We are wondering if the variable is being passed correctly in the last instance. As you are copying it into the script console and it is working, you must have replaced the variable to make it work. Can you provide a full deployment log, and also maybe a screenshot of where your variable is defined.

Thanks!
Vanessa

I feel really silly about this but I was altering my deployment scripts and then choosing to redeploy the only release I had. As it turns out, changes to deployment scripts are not carried over on redeploying a release.

I created a new release and my changes were applied and now the post deploy script is working. I must have had a typo in the post deploy script the first time I wrote it.

So if anyone else stumbles across this, if you are making changes to your deployment steps, you must issue a new release each time to test it.