首页 > 解决方案 > 为 Bitbucket 自定义管道部署值使用变量

问题描述

我正在尝试使用传递给自定义管道的变量为步骤设置部署变量。这个想法是不必复制自定义管道,因为唯一的变化是从 bitbucket 设置中读取的部署变量。

定义如下,但抛出错误

pipelines:
  custom:
    my-pipeline:
       - variables:   
          - name: deployment
       - step: 
           deployment: $deployment 
           script:
             - ...

我在这里遗漏了什么,还是部署密钥不允许接受变量?

标签: bitbucket-pipelines

解决方案


不幸的是,您不能在该deployment字段中使用变量。变量仅在字段中可用script。但是,您的问题可以通过另一种方式轻松解决:锚点

例如:

definitions:
  steps:
    - step: &Test-step
        name: Run tests
        script:
          - npm install
          - npm run test
    - step: &Deploy-step
        name: Deploy to staging
        script:
          - npm install
          - npm run build
          - fab deploy
pipelines:
  default:
    - step: *Test-step
    - step:
        <<: *Deploy-step
        name: Deploy to Staging
        deployment: staging
        trigger: manual
  custom:
    Staging Deployment
      - step: *Test-step
      - step:
          <<: *Deploy-step
          deployment: staging
    Production Deployment
      - step: *Test-step
      - step:
          <<: *Deploy-step
          deployment: production

推荐阅读