【发布时间】:2020-09-09 02:09:18
【问题描述】:
我正在尝试创建一个简单的 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 运行,同样的代码也可以正常工作。
我在这里错过了什么?
【问题讨论】:
-
您是否尝试将其更改为
cd $(Agent.BuildDirectory)/tools,然后运行dotnet-stryker? -
不是选项,因为我需要能够从特定的工作目录运行此任务。
-
这个问题怎么样?下面的答案是否解决了您的问题,如果没有,请告诉我有关此问题的最新信息吗?
-
@LeoLiu-MSFT 它没有解决我的问题。刚刚发布了我自己的答案。
标签: powershell azure-devops azure-pipelines