You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PowerShell Core的AzureCLI部署Synapse对象时遇语法错误

解决PowerShell Core中Azure CLI部署Synapse对象的Here-String语法错误

问题场景

使用Azure DevOps的AzureCLI@2任务,通过PowerShell Core部署Synapse数据集时,执行以下YAML配置出现报错:

- task: AzureCLI@2
  inputs:
    azureSubscription: 'ServiceConnection'
    scriptType: 'pscore'
    scriptLocation: 'inlineScript'
    inlineScript: 'az synapse dataset create --workspace-name SynapseWorkspaceName --name SQLServer1 --file @"$(System.DefaultWorkingDirectory)/dataset/SqlServer.json"'

错误信息:

No characters are allowed after a here-string header but before the end of the line.

已知相同命令在本地PowerShell、Azure DevOps Bash脚本环境中可正常运行,仅在PowerShell Core inline脚本中传递JSON文件名时出错。

解决方案

方案1:移除不必要的Here-String语法

--file参数仅需直接传入文件路径,无需使用PowerShell的Here-String(@"),修改inlineScript内容即可:

- task: AzureCLI@2
  inputs:
    azureSubscription: 'ServiceConnection'
    scriptType: 'pscore'
    scriptLocation: 'inlineScript'
    inlineScript: 'az synapse dataset create --workspace-name SynapseWorkspaceName --name SQLServer1 --file "$(System.DefaultWorkingDirectory)/dataset/SqlServer.json"'

方案2:拆分路径变量(可选,更清晰)

如果需要更清晰的脚本结构,可先将文件路径赋值给变量,再传入命令:

- task: AzureCLI@2
  inputs:
    azureSubscription: 'ServiceConnection'
    scriptType: 'pscore'
    scriptLocation: 'inlineScript'
    inlineScript: |
      $datasetPath = "$(System.DefaultWorkingDirectory)/dataset/SqlServer.json"
      az synapse dataset create --workspace-name SynapseWorkspaceName --name SQLServer1 --file $datasetPath

错误原因

PowerShell的Here-String语法要求@"必须是该行的最后内容,不能在同一行后续添加任何字符。原命令中@"后直接拼接文件路径,违反了该语法规则,导致解析报错。而Bash环境无此语法限制,本地PowerShell若为多行执行或正确格式的Here-String则可正常运行,因此出现场景差异。

内容的提问来源于stack exchange,提问作者Prawin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 13:37:22