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:
<span>tenant1</span><span>tenant2</span>
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:
- A developer or QA runs the Test custom pipeline.
- They select which tenant they want to deploy to (
<span>tenant1</span> or <span>tenant2</span>). - The pipeline should automatically resolve:
- Tenant-specific values from the selected Deployment Variables
- Common values from Repository Variables
- All pipeline steps should remain the same; I don't want to duplicate the pipeline or deployment logic for each tenant.
For example:
<span>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</span>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:
<span>pipelines:
custom:
deploy-test:
- variables:
- name: TENANT
allowed-values:
- tenant1
- tenant2
- step:
deployment: $TENANT
script:
- ./deploy.sh</span>I understand that <span>deployment:</span> 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.