Easily share data between steps in Bitbucket Pipelines

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

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.

Exit mobile version