Bitbucket Pipelines- Same Steps but against different environment variables(Deployment)
Asked by Midhun Mohan:

I have a use case like below

- we have a **release** branch

- Defined steps for build and deploy to destination from **release** branch in bitbucket-pipelines.yml

- Defined 3 different Destination as **testing,** **staging** and **production**

Question is, can we run pipeline against different destination but using the same release branch commit and same steps of build and deployment.


Answers:
author: Theodora Boudale
body: Hi [@Midhun Mohan](/t5/user/viewprofilepage/user-id/4316367) and welcome to the community.

When you say that you defined 3 different destinations as **testing** , **staging** and **production** , I assume that you defined them as ++deployment environments++ from **Repository settings \> Deployments**?

If so, you can define different variables for each deployment environment from this page.

Based on the description of your use case, you could configure the bitbucket-pipelines.yml file as follows:

```
pipelines:
  branches:
    release:
      - step:
          name: Build
          script:
            - <command 1>
            - <command 2>
      - step:
          name: Deploy to testing
          deployment: testing
          script:
            - <command to deploy>
      - step:
          name: Deploy to staging
          deployment: staging
          script:
            - <command to deploy>
      - step:
          name: Deploy to production
          deployment: production
          script:
            - <command to deploy>
```

With a yml file like above, each push to the **release** branch will trigger the Build step, and then the deployment steps to the 3 different environments.

I'm not sure if your question is about something different. In case I have misunderstood what you are asking, please feel free to clarify so I can better help you.

Kind regards,  
Theodora

comments: author: Midhun Mohan
body: Thanks for the response,

The mentioned steps, we already tried and its working.

The scenario here is bit different, means we have a build script, only those environment related variables has to be changed for each deployment(to dev , staging etc). So, if there is any way without updating yml each time for a new environment( say staging-2) we can run the pipeline. Only effort will be configuring the new environment under deployments.

Just to be simple, we need to check with you that can we select a deployment from a dropdown when running a pipeline so that the variables will be used from that.


author: Theodora Boudale
body: Hi [@Midhun Mohan](/t5/user/viewprofilepage/user-id/4316367),

Thank you for your reply and the clarification.

If you want to add and use a new environment under Deployments, then this needs to be added in the bitbucket-pipelines.yml file as well, with the keyword **deployment** for the relevant step.

Pipelines builds run based on the content of the bitbucket-pipelines.yml file and at the moment the deployment environment needs to be stated explicitly in the bitbucket-pipelines.yml file for the relevant step.

I'm afraid that it is not possible to have a deployment step where you can choose the environment from a dropdown.

Kind regards,  
Theodora


author: Midhun Mohan
body: ya got to know that few days before, thanks for the confirmation.


author: Brigitte Bedard
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) You know you can't do that, right? You can only define a particular deployment environment ONCE per pipeline.

As per BB customer support

<https://community.atlassian.com/t5/Bitbucket-questions/Usage-of-Deployment-variables-on-multiple-steps/qaq-p/1103443?anon_like=1313162>


author: Theodora Boudale
body: Hi Brigitte!
> You can only define a particular deployment environment ONCE per pipeline.

None of my replies here mention the opposite, the topic discussed in this question is different.

Kind regards,  
Theodora


Tags: bitbucket-cloud

bitbucket-pipelines

cloud