Search code examples
powershelloctopus-deploy

Powershell script failing in Octopus


I have a powershell script in my octopus process to run a powershell script on a server. When I run the script on the server itself it runs fine. When I try to incorporate the script in the octopus deploy process it just hangs and does not run. It gets as far as line 8 and just hangs.

Is there something on line 8 that I am not seeing. The line that starts with $process

Write-Host "Executing Protractor cmdline: & "$TestProtractorPathAndName" 
$TestProtractorArgs "
if (test-path $TestProtractorResultPath) {Remove-Item –path 
"$TestProtractorResultPath" –recurse}
New-Item -ItemType "directory" -path "$TestProtractorResultPath"
$args = "$TestProtractorArgs" 
Write-Host "Run Protractor scripts"
Write-Host $TestProtractorResultFile
Write-Host $TestProtractorResultFileLabel
$process = Start-Process "$TestProtractorPathAndName" $args -Wait - 
PassThru
Write-Host 'Exit code = $($process.ExitCode)'
New-OctopusArtifact -Path "$TestProtractorResultFile" -Name 
"$TestProtractorResultFileLabel"
if ($process.ExitCode -eq 0){
  Write-Host "Protractor cmdline complete"
} else {
  Write-Error "Protractor cmdline failed"
}

Solution

  • The problem is potentially a permissions issue - a difference in permissions between the interactive account that can run the script in person on the machine, and the tentacle that is installed and running as a service on the machine.

    The best way to iron out these issues is to simulate running your script as a tentacle. This can easily be achieved in Octopus Deploy using the Script Console feature.

    enter image description here

    Here you can write your PowerShell script and execute it on a tentacle, rather than running it using an interactive session on the deployment target - it will give you a much clearer picture when trying to troubleshoot issues like this.

    enter image description here

    Hope this helps