Uploaded image for project: 'Bitbucket Cloud'
  1. Bitbucket Cloud
  2. BCLOUD-20821

Add support for step-specific environment variables

    XMLWordPrintable

Details

    • Our product teams collect and evaluate feedback from a number of different sources. To learn more about how we use customer feedback in the planning process, check out our new feature policy.

    Description

      Right now, the only way (at least that I know of) to define step specific variables is to use deployments, but sometimes it might be useful to define variables for non-deployment steps as well. Defining some environment variables inside bitbucket-pipelines.yml for any step would be really useful for writing re-usable steps when using YAML anchors.

      In our use case, we have a monorepo that contains frontend code, backend code, iac code etc. and we use build flags to build multiple applications from the same source code and deploy each of them to separate cloud environments, all from the same branch. Because there's no easy way to re-use our step definitions, there's a lot of duplication in the pipelines configuration that could be easily reduced if we could pass env variables to steps.

      Here's a simplified example and a suggestion for syntax:

      image: atlassian/default-image:2
      
      definitions:
        steps:
          - step: &build
              name: build
              script:
                - ./install
                - ./lint
                - ./test
                - ./build $BUILD_TARGET
      
      pipelines:
        default:
          - step:
              name: Build (target 1)
              env:
                - BUILD_TARGET: 'build-target-1'
              <<: *build
          - step:
              name: Build (target 2)
              env:
                - BUILD_TARGET: 'build-target-2'
              <<: *build
      

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            c8e83515043a teel
            Votes:
            72 Vote for this issue
            Watchers:
            42 Start watching this issue

            Dates

              Created:
              Updated: