Vano
Vano

Reputation: 1538

programmatically lock GitLab branch

Background: We'd like to lock branch for merging while deploy Jenkins job is running

Question: Is there way to programmatically lock GitLab branch?
e.g. To set "maintainers_can_push": false" on GitLab protected branch

Checked so far:

  1. Haven't found any mention of such functionality at GitLab plugin.
  2. Haven't found anything on GitLab branches API page

Upvotes: 1

Views: 1156

Answers (1)

phd
phd

Reputation: 94676

At https://docs.gitlab.com/ee/api/branches.html#protect-repository-branch there is a link to the page https://docs.gitlab.com/ee/api/protected_branches.html devoted to API calls for listing protected branches, protect and unprotect them.

To protect a branch call POST /projects/:id/protected_branches. For example

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" 'https://gitlab.example.com/api/v4/projects/5/protected_branches?name=*-stable&push_access_level=30&merge_access_level=30&unprotect_access_level=40'

Upvotes: 1

Related Questions