windows - 如何在执行时引用 AWS CodeDeploy 包中的文件?
问题描述
我想在我的 AWS CodeDeploy 程序包中包含一个数据库升级脚本,但我看不到如何指定它的路径。
我成功触发了 PowerShell 脚本,并且我有一个调用 sqlcmd.exe 的脚本,并且我想将一个脚本传递给 sqlcmd 以运行。
当我使用 Get-Location 打印出当前工作目录时,它显示C:\Windows\system32
. 所以似乎我能够引用它的唯一方法就是知道当前的包路径。
有没有办法确定部署脚本中当前的包路径?
编辑 - 我的设置
version: 0.0
os: windows
files:
- source: .\source
destination: C:\inetpub\gentest.vanhookservice.com\dev
hooks:
BeforeInstall:
- location: .\scripts\db-backup-test.ps1
timeout: 6000
- location: .\scripts\code-backup-gentest.ps1
timeout: 6000
runas: Administrator
- location: .\scripts\db-upgrade-test.ps1
timeout: 6000
db-upgrade-test.ps1
:_
# Fail on all errors
$ErrorActionPreference = 'Stop'
# 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
}
echo "Upgrading test database..."
sqlcmd.exe -S vhs-awsdev-sql1 -d JobManagerDev -i ..\database\upgrade.sql
# Test if the sqlcmd.exe command exited with a success or error condition
if ($? -eq "False")
{
throw "sqlcmd.exe failed with exit code $LastExitCode"
}
echo "Test database upgrade complete."
问题是..\database\upgrade.sql
参考。我也尝试过.\database\upgrade.sql
,因为这就是脚本的引用方式appspec.yml
,但真正的问题是当前工作目录实际上是C:\Windows\system32
解决方案
只需将脚本保存在源代码的根目录中并指定如下:
version: 0.0
os: windows
files:
- source: \index.html
destination: c:\inetpub\wwwroot
hooks:
BeforeInstall:
- location: \before-install.bat # <====== script in source dir root
timeout: 900
详情在这里:
[1] 第 2 步:配置您的源内容以部署到 Windows Server Amazon EC2 实例 - 添加应用程序规范文件 - https://docs.aws.amazon.com/codedeploy/latest/userguide/tutorials-windows-configure- content.html#tutorials-windows-configure-content-add-appspec-file
推荐阅读
- websocket - Vert.x SockJSHandler 类
- javascript - 检索多个值本地存储并在 div 元素中显示
- database - 如何加入编辑发布 DynamoDB(性能)
- c# - When should I use navigation properties to query the database?
- r - R:ggsurvplot 如何在 start.time(2 年)之前删除平线
- java - 为什么发送和接收 POST 请求之间的字符编码不匹配?
- react-native - 使用“npm start”命令启动 Expo DevTools 后出现错误
- c# - 如何在没有实体框架的情况下连接到 ASP.NET Core 中的数据库?
- firebase - 为什么颤振不捕捉firebase存储文件未找到错误?
- c# - 保存到多个表的正确解决方案