如何在 YAML 中重用列表条目锚点?
How to reuse list entry anchor in YAML?
我正在尝试编写一个 CircleCI 配置,它允许我重用的不是整个条目(例如完整的 docker
部分定义)而是列表中的单个条目(例如使用过的 docker 图像)
假设我需要在几个地方重复使用 alpine
的图像
docker:
- image: alpine:3.10
environment:
LATENCY: 0
我希望能够定义不同的堆栈:
docker:
- image: postgres:12
- image: spotify/kafka:latest
- image: redis:2.8.23
并将上面定义的 alpine
图像放入此列表中。
我试过例如
docker:
- &default image: alpine:3.10
environment:
LATENCY: 0
build-step:
docker:
- *default
- image: postgres:12
但这不起作用。
我该怎么做?
如果你这样做:
docker:
- &default image: alpine:3.10
environment:
LATENCY: 0
那么锚 default
将指向字符串 alpine
.
如果要为映射(或序列)创建锚点,则锚点必须在其自己的行上:
docker:
- &default
image: alpine:3.10
environment:
LATENCY: 0
然后您就可以像以前一样使用它了:
build-step:
docker:
- *default
- image: postgres:12
我正在尝试编写一个 CircleCI 配置,它允许我重用的不是整个条目(例如完整的 docker
部分定义)而是列表中的单个条目(例如使用过的 docker 图像)
假设我需要在几个地方重复使用 alpine
的图像
docker:
- image: alpine:3.10
environment:
LATENCY: 0
我希望能够定义不同的堆栈:
docker:
- image: postgres:12
- image: spotify/kafka:latest
- image: redis:2.8.23
并将上面定义的 alpine
图像放入此列表中。
我试过例如
docker:
- &default image: alpine:3.10
environment:
LATENCY: 0
build-step:
docker:
- *default
- image: postgres:12
但这不起作用。
我该怎么做?
如果你这样做:
docker:
- &default image: alpine:3.10
environment:
LATENCY: 0
那么锚 default
将指向字符串 alpine
.
如果要为映射(或序列)创建锚点,则锚点必须在其自己的行上:
docker:
- &default
image: alpine:3.10
environment:
LATENCY: 0
然后您就可以像以前一样使用它了:
build-step:
docker:
- *default
- image: postgres:12