Make step deployment accessible as BITBUCKET_DEPLOYMENT variable in script

Issue #15987 open
Yury V. Zaytsev
created an issue

Environment variables available from pipeline steps are listed here:

https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html

There doesn't seem to be a way to find out which deployment environment is set for this step at the moment (i.e., via fictional BITBUCKET_DEPLOYMENT variable). It is needed for deployment script to decide what to do; otherwise, steps can't be reused for different environments.

This enhancement is trivial to implement but will provide a great value, because it will dramatically facilitate the reuse of scripts, given that current abilities are limited to YAML anchors.

Comments (3)

  1. Matt Ryall staff

    Thanks for the suggestion, Yury. Something like this makes a lot of sense, just for consistency with the other variables we pass through.

    Can you please provide an example YAML file you could improve with this feature?

    I tried to do it, and couldn't come up with an example that can't be made just as short by just putting the deployment commands inside a script in your repo.

  2. Zrean Tofiq

    I also noticed this would be a nice feature to have. Here is an example of a YAML that could be made better. Imagine that the deploy script that's being run in the following pipe has if/else statements doing different things depending on environment.

    pipelines:
      default:
        - step:
            name: Deploy to Development
            deployment: test
            script:
              - export DEPLOYMENT_ENV=test
              - ./scripts/deploy
        - step:
            name: Deploy to Test
            deployment: staging
            trigger: manual
            script:
              - export DEPLOYMENT_ENV=staging
              - ./scripts/deploy
        - step:
            name: Deploy to Production
            deployment: production
            trigger: manual
            script:
              - export DEPLOYMENT_ENV=production
              - ./scripts/deploy
    

    If we had such a variable already I could use anchors to share these steps instead of repeating myself. Like so:

    definitions: 
      steps:
        - step: &deploy
            script:
              - ./scripts/deploy
    
    pipelines:
      default:
        - step:
            <<: *deploy
            name: Deploy to Development
            deployment: test
        - step:
            <<: *deploy
            name: Deploy to Test
            deployment: staging
            trigger: manual
        - step:
            <<: *deploy
            name: Deploy to Production
            deployment: production
            trigger: manual
    

    This is quite a simplified example, but in more complex scenarios it could help.

  3. Log in to comment