Home > Mobile >  How to create a branch restriction through Bitbucket (cloud) API
How to create a branch restriction through Bitbucket (cloud) API

Time:08-04

I am trying to create a branch restriction using below curl command but it is throwing a bad request. How can I create a working API call? This executed on Jenkins using sh and enclosed in double quotes ("").

curl -X POST -s 'https://api.bitbucket.org/2.0/repositories/$workspace/$repository/branch-restrictions' \
                        --header 'Authorization: Bearer $token' \
                        --header 'Accept: application/json' \
                        --header 'Content-Type: application/json' \
                        --data '{\"type\" : \"branchrestriction\",\"links\": {\"self\": {\"href\": \"https://api.bitbucket.org/2.0/repositories/$workspace/$repository/branch-restrictions\",}},\"kind\":\"push\",\"branch_match_kind\": \"branching_model\",\"branch_type\": \"feature\",\"pattern\": \"feature/*\",\"users\": [\"$user\"],\"groups\": []}'

CodePudding user response:

I was able to successfully add branch restriction by removing other field due to incompatibility with other fields. See below changes.

curl -X POST -s 'https://api.bitbucket.org/2.0/repositories/$workspace/$repository/branch-restrictions'
--header 'Authorization: Bearer $token'
--header 'Accept: application/json'
--header 'Content-Type: application/json'
--data '{"type" : "branchrestriction","kind":"push","branch_match_kind": "glob","pattern": "feature/*","users": [],"groups": []}

  • Related