I have a simple Bitbucket Pipelines configuration:
image: node:12.16.3
pipelines:
pull-requests:
'**':
- step:
caches:
- node
script:
- yarn install
- yarn test
The test
script produces code coverage from Jest (jest --coverage
).
I have tried to send this coverage data to the Reports API by adding the following line after - yarn test
(please note, this is example code copied from Bitbuck docs, I haven't updated it to be specific to my data yet as I want to get the config valid, before trying to figure out what exactly needs to do into the data)
- curl --request PUT 'https://api.bitbucket.org/2.0/repositories/<username>/<reposity-name>/commit/<commit-hash>/reports/mySystem-001' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "Security scan report",
"details": "This pull request introduces 10 new dependency vulnerabilities.",
"report_type": "SECURITY",
"reporter": "mySystem",
"link": "http://www.mySystem.com/reports/001",
"result": "FAILED",
"data": [
{
"title": "Duration (seconds)",
"type": "DURATION",
"value": 14
},
{
"title": "Safe to merge?",
"type": "BOOLEAN",
"value": false
}
]
}'
Bitbucket keeps telling me that my configuration file is invalid - even though I've copied this code directly from their docs page.
Is it possible to send this code coverage data to the Bitbucket Reports API for the associated pull request? And if so, how do I craft that Pipelines yaml entry?
Jest code coverage reports are different format, you need to convert them into this format:
{
"files": [
{
"path": "backend/src/app.ts",
"coverage": "C:51,52;P:53;U:54,55"
}
]
}
The API endpoint you are using also doesn't seem right. It should be a POST request as mentioned in the plugin docs:
https://bitbucket.org/atlassian/bitbucket-code-coverage/src/master/code-coverage-plugin/README.md
It's a bit different if you're using Bitbucket cloud or Bitbucket server.
On Bitbucket cloud, you need to:
Adapting the example from bitbucket should look something like this:
curl --proxy 'http://localhost:29418' \
-X PUT "http://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/commit/${BITBUCKET_COMMIT}/reports/mySystem-001" \
-H 'Content-Type: application/json' \
-d '{
"title": "Security scan report",
"details": "This pull request introduces 10 new dependency vulnerabilities.",
"report_type": "SECURITY",
"reporter": "mySystem",
"link": "http://www.mySystem.com/reports/001",
"result": "FAILED",
"data": [
{
"title": "Duration (seconds)",
"type": "DURATION",
"value": 14
},
{
"title": "Safe to merge?",
"type": "BOOLEAN",
"value": false
}
]
}'
Reference | Link |
---|---|
Authentication | https://support.atlassian.com/bitbucket-cloud/docs/code-insights/#Authentication |
Default pipeline env | https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/#Default-variables |
Report Creation API | https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/commit/%7Bcommit%7D/reports/%7BreportId%7D#put |
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With