你通常会在 YAML 中看到两件事
- 序列 — 在其他编程语言中,这通常称为数组、列表等:
- apple
- banana
- pear
- 映射 — 在其他编程语言中,这通常被称为对象、散列、字典、关联数组……:
question: how do I foobar?
body: Can you help?
tag: yaml
因此,如果您想存储映射的映射,您可以这样做:
pier1:
boat: yes
in_activity: yes
comments: needs some painting in 2023
## The mapping above this comment refers to the pier1,
## as it is indented one level below the key `pier1`
pier2:
boat: no
in_activity: no
comments: currently inactive, needs urgent repair
## The mapping above this comment refers to the pier2,
## as it is indented one level below the key `pier2`
虽然,如果您将列表存储在映射中,则实际上可以不使用缩进:
fruits:
- apple
- banana
- pear
严格等于
fruits:
- apple
- banana
- pear
但是,如果您只想缩进管道的第一步,如下所示:
pipelines:
default:
- step:
deployment: production
您最终得到了一个有效的 YAML,但是,一个不再具有相同含义的 YAML。
当您的原始 yaml 表示:我确实有一个包含操作列表的默认管道,第一个操作是包含部署到生产的步骤。
生成的错误缩进 YAML 意味着:我确实有一个带有操作列表的默认管道,第一个操作有两个属性,第一个属性是一个空步骤,第二个属性是它是一个部署投入生产。
所以,在这里,实际上,作为步进映射属性的deplyement 键成为列表default 的第一个元素的属性!
要缩进所有这一切,你必须去:
pipelines:
default:
- step:
deployment: production
## ^-- This property is now further indented too
所以,你最终得到了 YAML:
image: atlassian/default-image:2
pipelines:
default:
- step:
deployment: production
script:
- git submodule update --recursive --init
- zip -r $FILENAME . -x bitbucket-pipelines.yml *.git*
- pipe: atlassian/bitbucket-upload-file:0.1.6
variables:
BITBUCKET_USERNAME: $BITBUCKET_USERNAME
BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
FILENAME: $FILENAME