6

I have a BitBucket Cloud repository with a WebHook to trigger Codefresh builds on Pull Requests. I would like the build results to appear as comments on the PRs, similar to the way Travis integration works for GitHub.

I couldn't find any settings for this in my BitBucket repository or in Codefresh, but Codefresh's documentation seems to suggest that this happens automatically when you setup integration with GitHub.

I can't find any examples of BitBucket repository with automatic comments. Is it supported?

030
  • 13,235
  • 16
  • 74
  • 173
aebabis
  • 161
  • 3

1 Answers1

3

One could update the build status in bitbucket as follows:

Adding a build result to a commit

To associate a build result with a particular commit, you need to POST a JSON object to the build status REST resource at:

https://<bitbucket-base-url>/rest/build-status/1.0/commits/<commit-hash>

The format of the JSON object that should be used as the request body is:

{
    "state": "<INPROGRESS|SUCCESSFUL|FAILED>",
    "key": "<build-key>",
    "name": "<build-name>",
    "url": "<build-url>",
    "description": "<build-description>"
}

One could run such a snippet by codefresh at the end of the build using a script to notify bitbucket regarding the build status of a commit.

One green build

The following curl command will add a build to the commit 9e72f04322c4a1f240e0b3158c67c3c19cdd16e7:

curl -u username:password -H "Content-Type: application/json" -X POST
http://localhost:7990/bitbucket/rest/build-status/1.0/commits/9e72f04322c4a1f240e0b3158c67c3c19cdd16e7
-d @build0.json

Where build0.json contains:

{
    "state": "SUCCESSFUL",
    "key": "REPO-MASTER",
    "name": "REPO-MASTER-42",
    "url": "https://bamboo.example.com/browse/REPO-MASTER-42",
    "description": "Changes by John Doe"
}
030
  • 13,235
  • 16
  • 74
  • 173