Bitbucket管道配置问题

时间:2019-02-15 15:10:08

标签: yaml bitbucket bitbucket-pipelines

在我的bitbucket-pipelines.yml文件中添加锚点之后,我得到了:

配置错误 您的bitbucket-pipelines.yml文件中的“主”部分缺少“步骤”。请添加缺少的“步骤”以纠正错误。

但是,根据https://bitbucket-pipelines.prod.public.atl-paas.net/validator,该配置为有效

image: node:latest
definitions:
  caches:
    node: ./node_modules
  steps:
    - step: &Test-step
        name: Run tests
        script:
          - npm install
          - npm run test
    - step: &Deploy-step
        caches:
          - node
        script:
          - sh bin/pipeline/backend-url-replace.sh
          - npm run build
          - sh bin/pipeline/deployment.sh
    - step: &E2E-step
        name: E2E tests
        caches:
          - node
        image: cypress/base:10
        script:
          - set +e; npm run cy:test
          - sh bin/pipeline/cypress-media-cp.sh
pipelines:
  branches:
    master:
      - step: *Test-step
      - step:
        <<: *Deploy-step
        name: Deploy to Test
        deployment: test
      - step:
        <<: *Deploy-step
        name: Deploy to Staging
        trigger: manual
        deployment: staging
    release/*:
      - step: *Test-step
      - step:
        <<: *Deploy-step
        name: Deploy to Staging
        deployment: staging

我在做什么错了?

2 个答案:

答案 0 :(得分:1)

这有时是由于缩进问题而发生的。

您可能需要将每个step下的列表缩进到四个空格(当前为两个):

pipelines:
  branches:
    master:
      - step: *Test-step
      - step:
          <<: *Deploy-step
          name: Deploy to Test
          deployment: test
      - step:
          <<: *Deploy-step
          name: Deploy to Staging
          trigger: manual
          deployment: staging
    release/*:
      - step: *Test-step
      - step:
          <<: *Deploy-step
          name: Deploy to Staging
          deployment: staging

答案 1 :(得分:0)

@AndroidNoobie解决了您的问题,但没有解释正在发生的事情。

在定义中,您缩进了映射,该映射是step的值:

- step: &Deploy-step
    caches:
      - node
    script:
      - sh bin/pipeline/backend-url-replace.sh
      - npm run build
      - sh bin/pipeline/deployment.sh

即键cachesscript的缩进比step缩进,这与锚是否存在无关。因此,这是一个序列元素,它与单个键step映射。

如果您要写:

- step: 
  caches:
    - node
  script:
    - sh bin/pipeline/backend-url-replace.sh
    - npm run build
    - sh bin/pipeline/deployment.sh

这是有效的YAML,您的序列元素仍然是一个映射,但是现在它具有三个键stepcachesscriptstep的值为null(那里可能有一个锚点,没有区别)。

这就是您的pipelines部分中的内容。您的合并键<<不是映射中的第一个键(也不一定是)。

例如您示例中的最后一个元素是具有五个值的映射,而不是具有一个键rest的映射,而该键的值是具有四个键的映射,这正是您所需要的。

相关问题