Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using Deployment Variables Based on Tenant Selection in a Bitbucket Custom Pipeline

Dattatray Sable
Banned
August 14, 2026

I have a Bitbucket custom pipeline that consists of multiple steps. The deployment steps and pipeline logic are the same for multiple test tenants; only the tenant-specific configuration differs.

My requirement is to configure two deployment environments, for example:

  • tenant1
  • tenant2

I want to store tenant-specific values such as Azure client ID, client secret, tenant ID, subscription ID, etc. as Deployment Variables for each environment.

At the same time, I have some common/shared values that should remain as Repository Variables.

The desired flow is:

  1. A developer or QA runs the Test custom pipeline.
  2. They select which tenant they want to deploy to (tenant1 or tenant2).
  3. The pipeline should automatically resolve:
    • Tenant-specific values from the selected Deployment Variables
    • Common values from Repository Variables
  4. All pipeline steps should remain the same; I don't want to duplicate the pipeline or deployment logic for each tenant.

For example:

Custom Test Pipeline
        |
        |-- Select Tenant
        |      |
        |      +-- tenant1
        |      |      └── Tenant 1 Deployment Variables
        |      |
        |      +-- tenant2
        |             └── Tenant 2 Deployment Variables
        |
        +-- Same pipeline steps
               |
               +-- Shared values → Repository Variables
               +-- Tenant values → Deployment Variables

Is there a supported way in Bitbucket Pipelines to dynamically select a Deployment environment based on a custom pipeline variable, so that the selected environment's Deployment Variables are automatically made available to all steps?

For example, something conceptually like:

pipelines:
  custom:
    deploy-test:
      - variables:
          - name: TENANT
            allowed-values:
              - tenant1
              - tenant2

      - step:
          deployment: $TENANT
          script:
            - ./deploy.sh

I understand that deployment: may need to be statically defined in the YAML. If dynamic selection is not supported, what would be the recommended Bitbucket approach for this use case while avoiding duplication of the actual deployment steps?

I would particularly like to keep the secrets in Deployment Variables rather than Repository Variables, since they are tenant-specific.

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events