Solution skill
Make variable visible across steps in Bitbucket pipelines?
Complete solution
Guide Make variable visible across steps in Bitbucket pipelines?: April 2025: now it's possible without tricks You can now export variables and use them in all subsequent steps as shown below. Use this when you hit exactly this in this tool. Not for different errors or different tools.
TL;DR: April 2025: now it's possible without tricks You can now export variables and use them in all subsequent steps as shown below. [code: pipelines: default: - step: name: Export Variable script: - echo "VAR1=12345" >> $BITBUCKETPIPELINESVARIABLESPATH output-variables: - VAR1 - step: name: Use Variable script: - echo $VAR1 ] The feature was first released and explained on 31st of March 2025: [Atlassian News Blog] Easily share data between steps in Bitbucket Pipelines .
April 2025: now it's possible without tricks You can now export variables and use them in all subsequent steps as shown below. [code: pipelines: default:
- step:
name: Export Variable script:
- echo "VAR1=12345" >> $BITBUCKETPIPELINESVARIABLESPATH
output-variables:
- VAR_1
- step:
name: Use Variable script:
- echo $VAR_1 ]
The feature was first released and explained on 31st of March 2025: [Atlassian News Blog] Easily share data between steps in Bitbucket Pipelines . This feature is explicitly meant to replace the old way:
Previously, sharing variables between steps required more effort than desired, doing things like saving variables in an artifact file and using that artifact in subsequent steps. With this new feature, you can now share variables seamlessly and efficiently, reducing complexity and potential errors in your pipeline configurations. ~ the Blog article
Read the docs: Output Variables step option (in Bitbucket Pipelines configuration reference).
Responding to a comment: it works with anchored steps, too. I tested it in a branch test-output-variables-and-anchors: [code: definitions: steps:
- step: &output-variables
name: Export Variable script:
- echo "VAR1=12345" >> $BITBUCKETPIPELINESVARIABLESPATH
- echo "VAR2=67890" >> $BITBUCKETPIPELINESVARIABLESPATH
output-variables:
- VAR_1
- VAR_2
- step: &log-variables
name: Log Variables script:
- echo $VAR_1
- echo $VAR_2
pipelines: branches: test-output-variables-and-anchors:
- step: *output-variables
- step: *log-variables ]
This worked and flawlessly did output the VAR_1 and VAR_2 values correctly in the second step.
When to use
You hit exactly this: Make variable visible across steps 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
the tool named in the title.
Edge cases
- With this new feature, you can now share variables seamlessly and efficiently, reducing complexity and potential errors in your pipeline configurations. ~ the Blog article Read the docs: Output Variables step option (in Bitbucket Pipelines configuration reference).
Evidence
Asked on Stack Overflow so:52481242: Stack Overflow #52481242 (score 61, accepted answer, 9 votes): I would like to share a variable across two steps.
I define it like:
[code: - export MYVAR="FOO-$BITBUCKETBUILD_NUMBER" ]
but then when I try to print it in other step:
[code: - echo $MY_VAR ]
it's empty.
How I can share such variable? The verified fix/answer: April 2025: now it's possible without tricks You can now export variables and use them in all subsequent steps as shown below. [code: pipelines: default:
- step:
name: Export Variable script:
- echo "VAR1=12345" >> $BITBUCKETPIPELINESVARIABLESPATH
output-variables:
- VAR_1
- step:
name: Use Variable script:
- echo $VAR_1 ]
The feature was first released and explained on 31st of March 2025: [Atlassian News Blog] Easily share data between steps in Bitbucket Pipelines . This feature is explicitly meant to replace the old way:
Previously, sharing variables between steps required more effort than desired, doing things like saving variables in an artifact file and using that artifact in subsequent steps. With this new feature, you can now share variables seamlessly and efficiently, reducing complexity and potential errors in your pipeline configurations. ~ the Blog article
Read the docs: Output Variables step option (in Bitbucket Pipelines configuration reference).
Responding to a comment: it works with anchored steps, too. I tested it in a branch test-output-variables-and-anchors: [code: definitions: steps:
- step: &output-variables
name: Export Variable script:
- echo "VAR1=12345" >> $BITBUCKETPIPELINESVARIABLESPATH
- echo "VAR2=67890" >> $BITBUCKETPIPELINESVARIABLESPATH
output-variables:
- VAR_1
- VAR_2
- step: &log-variables
name: Log Variables script:
- echo $VAR_1
- echo $VAR_2
pipelines: branches: test-output-variables-and-anchors:
- step: *output-variables
- step: *log-variables ]
This worked and flawlessly did output the VAR_1 and VAR_2 values correctly in the second step. Source: https://stackoverflow.com/questions/52481242/make-variable-visible-across-steps-in-bitbucket-pipelines
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_N6g09OSlMVCHpo9jQsOmnw" 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">Make variable visible across steps in Bitbucket pipelines? <span>— Vectle</span></a>