powershell - 如何在 Azure DevOps PowerShell 任务中使用预定义变量?
问题描述
我正在尝试创建一个简单的 Azure DevOps 扩展任务,该任务包括一个简单的 PowerShell 脚本,安装一个dotnet tool
然后像这样运行它:
dotnet tool install dotnet-stryker --tool-path $(Agent.BuildDirectory)/tools
$(Agent.BuildDirectory)/tools/dotnet-stryker
但是当我尝试运行我的任务时,我收到以下错误:
##[error]System.Management.Automation.ParseException: At D:\a\_tasks\run-stryker_400ea42f-b258-4da4-9a55-68b174cae84c\0.14.0\run-stryker.ps1:17 char:25
##[debug]Processed: ##vso[task.logissue type=error;]System.Management.Automation.ParseException: At D:\a\_tasks\run-stryker_400ea42f-b258-4da4-9a55-68b174cae84c\0.14.0\run-stryker.ps1:17 char:25
+ $(Agent.BuildDirectory)/tools/dotnet-stryker
+ ~
You must provide a value expression following the '/' operator.
At D:\a\_tasks\run-stryker_400ea42f-b258-4da4-9a55-68b174cae84c\0.14.0\run-stryker.ps1:17 char:25
+ $(Agent.BuildDirectory)/tools/dotnet-stryker
+ ~~~~~~~~~~~~~~~~~~~~
Unexpected token 'tools/dotnet-stryker' in expression or statement.
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at Microsoft.TeamFoundation.DistributedTask.Handlers.LegacyVSTSPowerShellHost.VSTSPowerShellHost.Main(String[] args)
##[error]LegacyVSTSPowerShellHost.exe completed with return code: -1.
我试图在我的代码中实现小的更改,例如更改\
和/
扭曲它,""
但我最终总是得到相同的结果。
请注意,如果我在 Azure Pipeline 中将其作为内联 PowerShell 运行,同样的代码也可以正常工作。
我在这里想念什么?
解决方案
在 PowerShell 脚本(内联)中,您需要使用以下语法:
$env:Agent_BuildDirectory
推荐阅读
- c++ - struct的指针以及如何访问元素
- jquery - 如何将 jQuery 变量传递给 Laravel Helper 参数?
- python - 查找由 scikit-image 的 blob_log(高斯拉普拉斯算子)方法识别的 blob 列表的平均像素值
- javascript - 在 jQuery 中增加 2 类名
- javascript - Angular:从不同的组件切换 HostBinding?
- ruby-on-rails - 使用 HTTParty 和 Ruby on Rails 使用分页的 Github API 数据
- r - R中的COSH距离
- javascript - 如何使箭头更改下拉的选定选项
- karate - For 循环在空手道的功能中没有按预期工作
- delphi - 在 lazarus 中安装 CCR.EXIF 包