如何在多行的“脚本"步骤中打破单个命令 [英] How to break a single command inside a `script` step on multiple lines
问题描述
我们有一个使用 Azure Pipeline 的项目,依赖于 repo 根目录下的 azure-pipelines.yml
文件.
We have a project using Azure Pipeline, relying on azure-pipelines.yml
file at the repo's root.
当实现一个script
步骤时,可以在同一个步骤中执行连续的命令,只需将它们写在不同的行上:
When implementing a script
step, it is possible to execute successive commands in the same step simply writing them on different lines:
- script: |
ls -la
pwd
echo $VALUE
然而,如果我们有一个很长的命令,我们希望能够在 YAML 文件中将它分成几行,但找不到相应的语法?
Yet, if we have a single command that is very long, we would like to be able to break it on several lines in the YAML file, but cannot find the corresponding syntax?
推荐答案
目前,我们发现在多行上打断单个命令的唯一方法是使用 YAML 折叠样式:p>
At the moment, the only way we found for to break a single command on multiple line is using YAML folded style:
- script: >
echo
'hello world'
这就是用 >
替换 |
.
注意事项:
- 不可能在以下几行中引入额外的缩进!例如,尝试对齐给定命令的所有参数会破坏行为.
- 此样式将用简单的空格替换提供的值中的换行符.这意味着脚本现在只能包含单个命令(也许在行尾添加文字
- It is not possible to introduce extra indentation on the following lines! For example, trying to align all arguments given to a command would break the behaviour.
- This style will replace newlines in the provided value with a simple white space. This means the script now can only contain a single command (maybe adding literal
这篇关于如何在多行的“脚本"步骤中打破单个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!