We’re excited to announce the release of a new feature in Bitbucket Pipelines designed to make it easier for you to share variables between steps within your workflows.
Overview
This feature allows you to define environment variables in one step and make them accessible in subsequent steps within the same pipeline.
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.
In the future, this variable sharing functionality will form the basis of additional features in Bitbucket Pipelines such as the ability to conditionally execute steps based on the values of certain shared variables.
Quick start
To enable variable sharing, you need to configure your pipeline YAML file. Here’s a basic example:
pipelines:
default:
- step:
name: Export Variable
script:
- echo "VAR_1=12345" >> $BITBUCKET_PIPELINES_VARIABLES_PATH
output-variables:
- VAR_1
- step:
name: Use Variable
script:
- echo $VAR_1
In this example, VAR_1
is defined in the first step and then used in the second step.
The output-variables
field specifies which variables can be shared. You must declare any variables that are to be exported in the output-variables section.
The value of any variables will be printed in the Build setup section of the logs for any subsequent steps.

Important considerations
- Variable naming: Multiple steps can write values to the same variable following a “last write wins” strategy.
- This was a conscious design decision in order to maximise ergonomics, especially for future use-cases like using variables in conditional expressions.
- If you want to ensure variable values are not overwritten by subsequent steps, provide step-specific names to your variables.
- Security: This feature is not intended for sharing secrets. There is a whole range of security risks that would be associated with doing so, including the fact that all shared variables will be logged in plain text in the build logs.
- Limits: There is a limit of 50 variables per pipeline, and shared variables within a pipeline can be up to 100kb in total size. Sharing large amounts of data between steps should be achieved using artifacts, or other means.
- Parallel steps: Variables should have unique names across parallel steps to avoid conflicts. See previous comment re: “Variable Naming” for context.
- Scope: These variables persist for the lifetime of a pipeline, so will be available when you re-run failed steps, but not when you rerun the entire pipeline (which creates a new pipeline).
Feedback
We’re always keen to hear your thoughts and feedback – if you have any questions or suggestions on this feature, feel free to share via the Pipelines Community Space.