Ask Your Question
1

How can I access the results of the quality gate in Bitbucket Pipelines?

asked 2023-07-20 23:25:32 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-20 23:39:01 +0000

scrum gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-20 23:25:32 +0000

Seen: 18 times

Last updated: Jul 20 '23