AWS CodeDeploy可以执行PowerShell脚本吗?

将Powershell脚本直接包含到appspec.yml文件中是否可以接受?

 version: 0.0 os: windows files: - source: ./MyWebsiteFiles destination: /MyWebsite hooks: AfterInstall: - location: /Scripts/MyScript.ps1 timeout: 300 

我正在运行一个ps1文件,该文件通过EC2实例上的Powershell控制台即时执行,但是我的部署在执行Powershell脚本时卡住或失败。

从CodeDeploy文档中我可以看到,似乎没有可以包含在appspec.yml文件中的可接受文件types的列表。

谢谢你的帮助。

是!

虽然我一直无法find可接受的脚本types的确定列表,但看起来答案是Yesappspec.yml .ps1脚本是可以接受的,如果包含在appspec.yml文件中,脚本将被执行。

我的Powershell脚本一直运行不正常,直到我按照@kafka的故障排除页面上的build议添加代码,所以我的脚本现在包含以下内容:

 # Are you running in 32-bit mode? # (\SysWOW64\ = 32-bit mode) if ($PSHOME -like "*SysWOW64*") { Write-Warning "Restarting this script under 64-bit Windows PowerShell." # Restart this script under 64-bit Windows PowerShell. # (\SysNative\ redirects to \System32\ for 64-bit mode) & (Join-Path ($PSHOME -replace "SysWOW64", "SysNative") powershell.exe) -File ` (Join-Path $PSScriptRoot $MyInvocation.MyCommand) @args # Exit 32-bit script. Exit $LastExitCode } # Was restart successful? Write-Warning "Hello from $PSHOME" Write-Warning " (\SysWOW64\ = 32-bit mode, \System32\ = 64-bit mode)" Write-Warning "Original arguments (if any): $args" # Your 64-bit script code follows here... # ... # # I PUT MY SCRIPT HERE # 

我仍然不确定我的脚本是否仅与64位版本的Powershell兼容,或者如何find它,但它适用于此修改。

我希望这有助于某人。

更新:关于文件位置的注释

我想强调一下运行.ps1脚本时遇到的问题。 根据我的经验, ps1脚本必须放置在部署包的根目录 (与appspec.yml文件位于同一文件夹位置),否则脚本可能无法执行,部署将在CodeDeploy中显示为“成功”。 更多信息在这里 。

是的,但可以,除非你设置一个variables在运行脚本时遇到的错误不会停止你的部署。

 $ErrorActionPreference = 'Stop' 

看到这个链接的更多细节:

https://aws.amazon.com/premiumsupport/knowledge-center/powershell-cmdlet-errors-codedeploy/