'Can I overwrite BitBucket environment variables on specific conditions?

I am trying to overwrite my repository secrets for Prod with Test credentials based on specific attributes provided as input to BitBucket Pipeline, however running into an issue.

if [[  “$parent_ou_id " == “xyz” ]]; then AWS_ACCESS_KEY_ID=“$TEST_AWS_ACCESS_KEY_ID” ; AWS_SECRET_ACCESS_KEY=“$TEST_AWS_SECRET_ACCESS_KEY” ; fi

Error

conditional binary operator expected


Solution 1:[1]

Okay, I assume your structure is something like;

pipelines:
    tags:
    '*-test*':
      - step:
          name: "beta step name"
          deployment: beta
          script:
            - <script>
    '*-prod':
      - step:
          name: "prod step name"
          deployment: prod
          script:
            - <script>

The important field here is deployment argument. You can define different deployment names for your environments and different variables with the same names.

As document points ;

You can add, edit, or remove variables at the account, repository, and deployment environment levels. If you use the same name as an existing variable, you can override it. The order of overrides is Deployment > Repository > Account > Default variables. Each deployment environment is independent so you can use the same variable name with different values for each environment.

https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Oguzhan Aygun