我正在尝试创建一个简单的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.我尝试在代码中实现一些小的更改,比如将\替换为/,并将其封装在""中,但最终总是得到相同的结果。
请注意,如果我以内联PowerShell的形式在Azure管道中运行相同的代码,那么这段代码工作得很好。
我在这里错过了什么?
发布于 2020-09-14 23:03:41
结果是,我的问题与Azure Devops变量无关,而是因为我试图像运行Powershell命令一样运行一个字符串。
用一个简单的Invoke-Expression解决了它。
Invoke-Expression "$(Agent.BuildDirectory)/tools/dotnet-stryker"发布于 2020-09-09 06:37:20
在PowerShell脚本(它是内联的)中,您需要使用以下语法:
$env:Agent_BuildDirectoryhttps://stackoverflow.com/questions/63803805
复制相似问题