Bitbucket Pipelines在分支机构之间共享一些步骤

Yar*_*awh 17 bitbucket bitbucket-pipelines

是否可以在分支之间共享步骤并仍然运行分支特定步骤?例如,开发和发布分支具有相同的构建过程,但上载到单独的S3存储桶.

pipelines:
  default:
    - step:
        script:
          - cd source
          - npm install
          - npm build
  develop:
    - step:
        script:
          - s3cmd put --config s3cmd.cfg ./build s3://develop

  staging:
    - step:
        script:
          - s3cmd put --config s3cmd.cfg ./build s3://staging
Run Code Online (Sandbox Code Playgroud)

我看到这篇文章(Bitbucket Pipelines - 具有相同步骤的多个分支)但它是相同的步骤.

Max*_*ysh 19

使用YAML锚点:

definitions:
  steps:
    - step: &Test-step
        name: Run tests
        script:
          - npm install
          - npm run test
    - step: &Deploy-step
        name: Deploy to staging
        deployment: staging
        script:
          - npm install
          - npm run build
          - fab deploy
pipelines:
  default:
    - step: *Test-step
    - step: *Deploy-step
  branches:
    master:
      - step: *Test-step
      - step:
        <<: *Deploy-step
        name: Deploy to production
        deployment: production
        trigger: manual
Run Code Online (Sandbox Code Playgroud)

文档:https://confluence.atlassian.com/bitbucket/yaml-anchors-960154027.html

  • 有一个功能:https://community.atlassian.com/t5/Bitbucket-questions/Is-it-possible-to-set-environment-variables-per-pipeline-step/qaq-p/941913 (2认同)

con*_*n-- 12

虽然它尚未得到官方支持,但您现在可以预先定义步骤.
当我遇到一个问题时,我从bitbucket工作人员得到了这个提示,跨越了一个分支子集.

 definitions:
  step: &Build
    name: Build
    script:
      - npm install
      - npm build

pipelines:
  default:
    - step: *Build
  branches:
    master:
      - step: *Build
      - step:
          name: deploy
          # do some deploy from master only
Run Code Online (Sandbox Code Playgroud)

它并不完美,但它总比没有好


Fin*_*sse 5

我认为 Bitbucket 做不到。您可以使用一个管道并检查分支名称:

pipelines:
  default:
    - step:
        script:
          - cd source
          - npm install
          - npm build 
          - if [[ $BITBUCKET_BRANCH = develop ]]; then s3cmd put --config s3cmd.cfg ./build s3://develop; fi
          - if [[ $BITBUCKET_BRANCH = staging ]]; then s3cmd put --config s3cmd.cfg ./build s3://staging; fi
Run Code Online (Sandbox Code Playgroud)

最后两行将仅在指定的分支上执行。