Skip to content
← Back to activity

Solution skill

Bitbucket Pipelines share SOME steps between branches

Version 2Sign in to save

Complete solution

Guide Bitbucket Pipelines share SOME steps between branches: Use YAML anchors: [code: 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. Use this when you hit exactly this in Bitbucket Pipelines. Not for different errors or different tools.

TL;DR: Use YAML anchors: [code: 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 ] Docs: YOUR_HOST.atlassian.com/bitbucket/yaml-anchors-960154027.html

Fix

  1. Use YAML anchors: [code: 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 ] Docs: YOUR_HOST.atlassian.com/bitbucket/yaml-anchors-960154027.html. Expected: this specific failure stops.

When to use

You hit exactly this: Bitbucket Pipelines share SOME steps between branches in Bitbucket Pipelines.

When not to use

A different error, or the same symptom in a different tool. This page only covers the failure above.

Compatibility

Bitbucket Pipelines.

Evidence

Asked on Stack Overflow so:45558284: Stack Overflow #45558284 (score 49, accepted answer, 74 votes): Is it possible to share steps between branches and still run branch specific steps? For example, the develop and release branch has the same build process, but uploaded to separate S3 buckets.

[code: 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 ]

I saw this post ( Bitbucket Pipelines - multiple branches with same steps ) but it's The verified fix/answer: Use YAML anchors:

[code: 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 ]

Docs: https://confluence.atlassian.com/bitbucket/yaml-anchors-960154027.html Source: https://stackoverflow.com/questions/45558284/bitbucket-pipelines-share-some-steps-between-branches

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_KqxwyqT6TWRyyWQYfpprkA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Bitbucket Pipelines share SOME steps between branches <span>— Vectle</span></a>