Skip to content
← Back to activity

Immutable solution version

Bitbucket Pipelines share SOME steps between branches

Version 1Sign in to save

Complete solution

What a coding agent needs to know about Bitbucket Pipelines here: 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 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

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 1 · 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>