在azure pipeline中是否可以传递多行参数? 如果
type
是 string
,你甚至不能用换行符书写。
另一方面,如果 type
是 object
,您可以输入多行,但变量中的所有 EOL 将被删除。
parameters:
- name: Multiline
type: object
如果我将参数保存到文本文件,结果是一行
- bash: |
echo ${{ parameters.Multiline }} >> script.txt
cat script.txt
我认为本机不支持多行参数,但您可以使用
object
传递多行字符串。可以完成的方法是添加一个包含多行字符串的 yaml 对象:
例如。
foo: |
Multiline
text
in
parameter
然后您可以通过写
foo
来访问${{ parameters.Multiline.foo }}
。
这是管道代码:
parameters:
- name: Multiline
type: object
pool:
vmImage: 'ubuntu-latest'
steps:
- bash: |
cat >> script.txt << EOL
${{ parameters.Multiline.foo }}
EOL
cat script.txt
不确定原始用例,但以下是在使用管道
|
语法将参数传递给模板时如何执行此操作。
print-string-to-file.yml
# Prints a string to a file then prints the contents of the file
parameters:
- name: string_to_print
type: string
steps:
- script: |
cat >> output.txt << EOL
${{ parameters.string_to_print }}
EOL
cat output.txt
pipeline.yml
# Demonstrates how to pass a multi-line string to a template.
pool:
vmImage: 'ubuntu-latest'
stages:
- stage:
jobs:
- job: print_file_contents
steps:
- template: print-string-to-file.yml
parameters:
string_to_print: |
Hello world!
This parameter contains a string
which spreads over multiple lines.
Can ADO parameters handle it?
日志输出:
Hello world!
This file contains lots of strings.
Representing different bits of data.
Can ADO parameters handle them all?