Incorrect "Next" URL Response for Repository Variables and Deployments Endpoints

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

When querying for repository variables and deployments on a repository with additional results, the pagination provides a "next" URL to query the remaining results. However, a bug has been identified where the "repository variables" endpoint returns incorrect URLs, leading to URLs like:

1 https://SOME_INVALID_DOMAIN_HERE/rest/1.0/accounts/... OR https://SOME_INVALID_DOMAIN_HERE/rest/2.0/accounts/...

This problem has already been reported as a bug: BCLOUD-20910 "Next" URL response for repository variables and deployments endpoints are incorrect.

We will discuss a workaround to list deployments and repository variables without relying on the API's incorrect "next" page URL.

Solution

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 pipelines: default: - step: script: - env > all_variables_step1 clone: enabled: false artifacts: - all_variables_step1 - step: script: - env > all_variables_step2 - diff <(grep -v '^#' all_variables_step1 | grep -vE '^(BITBUCKET_DEPLOYMENT_ENVIRONMENT|BITBUCKET_DEPLOYMENT_ENVIRONMENT_UUID)=.*$' | cut -d '=' -f 1) <(grep -v '^#' all_variables_step2 | grep -vE '^(BITBUCKET_DEPLOYMENT_ENVIRONMENT|BITBUCKET_DEPLOYMENT_ENVIRONMENT_UUID)=.*$' | cut -d '=' -f 1) | grep '^>' | sed 's/^> //' > deployment_variables - while IFS= read -r var; do value=$(printenv "$var"); echo "$var=$value" >> deployment_variables_values; done < deployment_variables - cat deployment_variables_values clone: enabled: false deployment: test artifacts: - deployment_variables - deployment_variables_values

The below-provided bitbucket-pipelines.yml can be used to capture environment variables from two different steps and then perform a comparison to identify the environment variables specific to a "test" deployment environment. Let's break down the script step by step:

Explanation:

  1. The pipelines section specifies the pipeline's configuration, and the default section indicates the default pipeline that runs when no specific branch or tag is matched.

  2. The first step, represented by - step:, captures all environment variables from the pipeline execution using the env command and saves them in a file named all_variables_step1. The clone section with enabled: false means the repository will not be cloned for this step since it only deals with environment variables and does not require the repository content.

  3. The artifacts section specifies that the all_variables_step1 file is preserved as an artifact, meaning it will be available for use in subsequent steps.

  4. The second step, also represented by - step:, captures all environment variables again using the env command and saves them in a file named all_variables_step2.

  5. The diff command is used to compare the differences between the environment variables captured in all_variables_step1 and all_variables_step2. The grep and cut commands are used to filter out specific environment variables that are not relevant to the "test" deployment environment (BITBUCKET_DEPLOYMENT_ENVIRONMENT and BITBUCKET_DEPLOYMENT_ENVIRONMENT_UUID).

  6. The grep '^>' command is used to extract the lines that represent the unique environment variables found in all_variables_step2 (those that are not present in all_variables_step1). The result is then saved in a file named deployment_variables.

  7. The while loop is used to read each line from the deployment_variables file and retrieve the values of the corresponding environment variables using the printenv command. The environment variable names and their values are then saved in a file named deployment_variables_values.

  8. The cat command is used to display the content of the deployment_variables_values file, showing the unique environment variables specific to the "test" deployment environment.

  9. The clone section with enabled: false means the repository will not be cloned for this step, similar to the first step.

  10. The deployment: test specifies that this step is associated with the "test" deployment environment.

  11. The artifacts section specifies that both deployment_variables and deployment_variables_values files are preserved as artifacts, making them available for further use or review.

Note that this bitbucket-pipelines.yml demonstrates the advanced usage of pipeline steps, such as artifacts, in combination with bash commands. Please test this in our test environment to validate its functionality before implementing it in your other environments.

Updated on March 3, 2025

Still need help?

The Atlassian Community is here for you.