我有一个PowerShell脚本来部署一些数据库代码。这是一个SSDT项目,它是这样的构成:构建部署脚本的最佳方法?
Root
\Deployment
\Scripts
Deploy.ps1
\Config
deploy.config
\SolutionRoot
\DatabaseProject
\UnitTestProject
做我的工作站上测试部署我更改为\Deployment\Scripts
和运行Deploy.ps1
并能正常工作。当我从Jenkins构建服务器运行它时,当前工作目录是根文件夹(不是脚本)。所以Deploy.ps1
脚本无法运行时调用,如:powershell -File Deployment\Scripts\Deploy.ps1
比如我有接近脚本的顶部,调试代码:
$currentDirectory = (Get-Item -Path ".\" -Verbose).FullName
Write-Host "Current Working Directory: $currentDirectory"
当我的工作站上运行它返回:
Current Working Directory: C:\repos\MyRoot\Deployment\Scripts
时生成服务器上运行,将会返回
Current Working Directory: D:\Jenkins\workspace\MyRootWithADifferentName
我希望脚本能够在任何地方运行,那么知道目录结构中的下落的最佳方式是什么?构建服务器可能会有所不同,并且根目录的名称可能也会有所不同,但其他所有服务器相对于根都是静态的。