AWS CodeDeploy 可以执行 powershell 脚本吗?

Luk*_*uke 6 deployment amazon-web-services

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

version: 0.0
os: windows
files:
  - source: ./MyWebsiteFiles
    destination: /MyWebsite
hooks:
  AfterInstall:
    - location: /Scripts/MyScript.ps1
      timeout: 300
Run Code Online (Sandbox Code Playgroud)

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

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

谢谢你的帮助。

Luk*_*uke 10

是的!

尽管我无法找到可接受的脚本类型的明确列表,但答案似乎是Yes- Powershell.ps1脚本是可接受的,如果包含在appspec.yml文件中,则会被执行。

在我按照@kafka 在故障排除页面上的建议添加代码之前,我的 Powershell 脚本无法始终如一地工作,因此我的脚本现在包含以下内容:

# 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
#
Run Code Online (Sandbox Code Playgroud)

我仍然不确定我的脚本是否只与 64 位版本的 Powershell 兼容或如何找到它,但它可以与此修改一起使用。

我希望这对某人有所帮助。

更新:关于文件位置的说明

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