powershell - 如何在 azure devops 中调用另一个目录的 powershell 脚本
问题描述
我正在尝试从子目录中的另一个 powershell 脚本调用 powershell 脚本。目录结构如下:
main_script.ps1
./Test:
. .. test.ps1
所以我从 test.ps1 调用 main_script.ps1 如下:
#Call the main script
../main_script.ps1
当我从具有相同结构的云外壳执行此操作时,我可以成功调用 main_script.ps1 脚本。但在 azure devops 中,我遇到以下错误:
##[error]The term '../main_script.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
您对正确的路径有任何想法吗?azure devops 任务的默认路径是什么?我正在使用 Azure Devops Release 来创建管道。
解决方案
看起来 workingDirectory 只是附加到脚本名称而不更改根目录。您可以内联克服此调用脚本:
steps:
- task: PowerShell@2 # this doesn't work
continueOnError: true
inputs:
targetType: 'filePath' # Optional. Options: filePath, inline
filePath: 'test.ps1'
workingDirectory: '$(Build.SourcesDirectory)/stackoverflow/77-powershell/'
- task: PowerShell@2 # this works
continueOnError: true
inputs:
targetType: 'inline' # Optional. Options: filePath, inline
script: |
cd '$(Build.SourcesDirectory)/stackoverflow/77-powershell/'
./test.ps1
推荐阅读
- c# - 如何在C#中获取一年的周开始日期(星期一)和结束日期(星期日)列表
- java - 新数组中的恒定步进值
- java - Java TCP Socket While循环和计数器接收数据X次
- firebase - 如何使用 ESP8266 监听 Firestore 的变化?
- class - “:”在 Dart 中是什么意思或做什么?
- java - 有没有更好的方法来处理深度嵌套数据的空异常?
- php - 我想在函数之外显示结果
- c# - 将项目作为复选框添加到组合框
- vimeo-android - 我想将 vimeo 视频与应用程序集成
- python - Flask-Admin:更改 inline_models 的排序顺序?