【问题标题】:Bitbucket Pipelines config issueBitbucket 管道配置问题
【发布时间】:2019-02-16 06:34:16
【问题描述】:

在我的 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

我做错了什么?

【问题讨论】:

    标签: yaml bitbucket bitbucket-pipelines


    【解决方案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
    

    【讨论】:

    • 没问题!我不知道为什么他们的验证者没有注意到这一点,但我已经看过几次了。
    【解决方案2】:

    @AndroidNoobie 解决了你的问题,但没有解释发生了什么。

    在您的定义中,您缩进作为 step 值的映射:

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

    即键cachesscriptstep 缩进更多,这与锚点是否存在无关。所以这是一个使用单个键 step 映射的序列元素。

    如果你会写:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-31
      • 2017-04-02
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      • 2022-09-02
      • 2017-11-06
      相关资源
      最近更新 更多