Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can access the results of the quality gate in Bitbucket Pipelines by adding a step to your pipeline that uses the Bitbucket REST API to retrieve the results of the Quality Gate.

Here are the steps you can follow:

  1. First, make sure that your pipeline is configured to run your quality gate. You can use tools like SonarQube or other quality gate tools to run your tests and generate quality gate results.

  2. Once your pipeline has run the quality gate, you can add a new step to your pipeline that retrieves the quality gate results.

  3. You can use the Bitbucket REST API to retrieve the quality gate results. The API endpoint is: https://<BITBUCKET_BASE_URL>/rest/insights/1.0/projects/<PROJECT_ID>/repos/<REPO_SLUG>/quality-gate/results/latest.

  4. You'll need to make sure that you have the necessary permissions to access the REST API endpoint. You can add an API key or OAuth token to your Bitbucket Pipelines settings to authenticate your requests.

  5. Once you've retrieved the quality gate results, you can use them in your pipeline to make decisions about whether to proceed with the build or deploy process.

Here's an example script that retrieves the quality gate results using the Bitbucket REST API:

- step:
    script:
      - export QUALITY_GATE_RESULT=$(curl -s -H "Authorization: Bearer $BITBUCKET_ACCESS_TOKEN" https://api.bitbucket.org/2.0/repositories/<USERNAME>/<REPO_SLUG>/pipelines/latest/result | jq '.variables | map(select(.key == "QUALITY_GATE_RESULT")) | .[0].value')
      - echo "Quality Gate Result: $QUALITY_GATE_RESULT"

This script retrieves the quality gate result from the latest pipeline run and stores it in the QUALITY_GATE_RESULT environment variable. You can then use this variable to make decisions about whether to proceed with the build or deploy process.