snippetMinor
How can I automatically post Codefresh build results to pull requests in Bitbucket?
Viewed 0 times
canpullautomaticallybitbucketcodefreshposthowresultsbuildrequests
Problem
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?
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?
Solution
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:
The format of the JSON object that should be used as the request body
is:
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:
Where build0.json contains:
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:///rest/build-status/1.0/commits/The format of the JSON object that should be used as the request body
is:
{
"state": "",
"key": "",
"name": "",
"url": "",
"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.jsonWhere 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"
}Code Snippets
{
"state": "<INPROGRESS|SUCCESSFUL|FAILED>",
"key": "<build-key>",
"name": "<build-name>",
"url": "<build-url>",
"description": "<build-description>"
}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{
"state": "SUCCESSFUL",
"key": "REPO-MASTER",
"name": "REPO-MASTER-42",
"url": "https://bamboo.example.com/browse/REPO-MASTER-42",
"description": "Changes by John Doe"
}Context
StackExchange DevOps Q#1049, answer score: 3
Revisions (0)
No revisions yet.