Is it acceptable to include Powershell scripts directly into the appspec.yml
files?
version: 0.0
os: windows
files:
- source: ./MyWebsiteFiles
destination: /MyWebsite
hooks:
AfterInstall:
- location: /Scripts/MyScript.ps1
timeout: 300
I'm running a ps1
file that executes instantly through the Powershell console on the EC2 instance, but my deployment is getting stuck or failing at the point of executing the Powershell script.
There doesn't appear to be a list of acceptable file types that can be included in an appspec.yml
file, from what I can see on the CodeDeploy documentation.
Thanks for your help.
Best Answer
YES!
Although I haven't been able to find a definitive list of the acceptable script types, it looks like the answer is
Yes
- Powershell.ps1
scripts are acceptable and will be executed if included in theappspec.yml
file.My Powershell script wasn't working consistently until I added the code as recommended on the troubleshooting page by @kafka, so my script now contains the following above it:
I am still unsure as to whether my script is only compatible with the 64 bit version of Powershell or how to find it out, but it works with this modification.
I hope that this helps someone.
Update: A note on file location
I'd like to highlight an issue that I faced with running
.ps1
scripts. From my experience,ps1
scripts must be placed at the root of your deployment package (the same folder location as your appspec.yml file), if not, your script may fail to execute and the deployment will display as 'Successful' in CodeDeploy. More info on this here.