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.
相关产品推荐
相关产品推荐

