Powershell script extracted from uploaded package

I’m currently trying to run a simple powershell script from a reference package that’s zipped. Every time the path to the script can’t be found and fails to run. Any advice would be appreciated.

Hi @sabrina.grosse,

Welcome to the Octopus community, I’d be happy to help with running scripts in a package!

It will change slightly depending on if the package was extracted, however we did design it to work with relative paths. Check out our docs which cover it here: Run a script step - Octopus Deploy

For example, a Package named “helloWorld” containing a script “hello-world.ps1” referenced in Step could use the following path: .\helloWorld\hello-world.ps1.

There are also a bunch of variables we expose for interacting with the package contents, check out the options here: Run a script step - Octopus Deploy

You can also run scripts as ‘Pre-deploy’ or ‘Post-Deploy’ where Octopus will detect scripts with specific names and invoke them at the specified time:
https://octopus.com/docs/deployments/custom-scripts/scripts-in-packages

Feel free to let me know if you have any questions or run into any issues!

Best Regards,

Here’s the script inline:
$ExtractedPath = $OctopusParameters[“Octopus.Action.Package[Acme].ExtractedPath”]
Write-Host “PWD: $PWD”
Write-Host “ExtractedPath: $ExtractedPath”

cd C:\Octopus\Work\20230222144732-37531-10\gamingScript

Powershell -File C:\Octopus\Work\20230222144732-37531-10\gamingScript\deploy.ps1

And here is the errors we are getting:
Extracting package ‘C:\Octopus\Files\gamingScript@S1.0.0.1@A04AE68462F6A441AC9C490C8F2BF99B.zip’ to ‘C:\Octopus\Work\20230222145600-37535-20\gamingScript’
PWD: C:\Octopus\Work\20230222145600-37535-20
ExtractedPath:
ObjectNotFound: Cannot find path ‘C:\Octopus\Work\20230222144732-37531-10\gamingScript’ because it does not exist.
At C:\Octopus\Work\20230222145600-37535-20\Script.ps1:5 char:1
cd C:\Octopus\Work\20230222144732-37531-10\gamingScript
at , C:\Octopus\Work\20230222145600-37535-20\Script.ps1: line 5
at , : line 1
at , C:\Octopus\Work\20230222145600-37535-20\Octopus.FunctionAppenderContext.ps1: line 211
at , C:\Octopus\Work\20230222145600-37535-20\Bootstrap.Octopus.FunctionAppenderContext.ps1: line 1532
at , : line 1
at , : line 1
The remote script failed with exit code 1
The action Run a Gaming Script on worker1-gaming failed

It’s saying that the gamingScript and deploy.ps1 don’t exist and I’m not sure how to access/run it since it’s already extracted.

Thanks for the help, we figured it out!

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.