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

AzureCLI@2任务多行Arguments参数配置失效问题咨询

解决AzureCLI@2任务多行Arguments不生效的问题

针对AzureCLI@2任务中Arguments多行字符串不生效的问题,这里提供两个无需修改脚本就能保持参数可读性的实用方案:

方法1:使用YAML折叠标量(>)

将原来的|替换为>,YAML会自动把多行内容合并为单行(换行符替换为空格),既保留YAML里的分行可读性,又能正确传递参数给PowerShell脚本:

- task: AzureCLI@2
  displayName: 'do thing'
  inputs:
    azureSubscription: $(myServiceConnection)
    scriptType: 'pscore'
    scriptLocation: 'scriptPath'
    scriptPath: 'myscript.ps1'
    arguments: >
       -arg1switch
       -arg2 aString
       -arg3 aString
       ...
       -argN aString

方法2:将参数定义为管道变量

把参数提前定义在variables块中,同样用折叠标量处理多行,再在任务中引用变量,适合参数需要复用的场景:

variables:
  myScriptArgs: >
    -arg1switch
    -arg2 aString
    -arg3 aString
    ...
    -argN aString

- task: AzureCLI@2
  displayName: 'do thing'
  inputs:
    azureSubscription: $(myServiceConnection)
    scriptType: 'pscore'
    scriptLocation: 'scriptPath'
    scriptPath: 'myscript.ps1'
    arguments: $(myScriptArgs)

原写法无效的原因

YAML的|符号会保留换行符,导致传递给PowerShell的参数中包含换行,被解析为无效格式;而>会自动将换行符折叠为空格,生成符合命令行要求的单行参数串。

内容的提问来源于stack exchange,提问作者Ryu S.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 11:40:12