背景: 我们希望在部署Jenkins作业运行时锁定分支以进行合并
问题:
有没有办法以编程方式锁定GitLab分支?
例如在GitLab受保护的分支上设置“ maintainers_can_push”:false”
到目前为止已检查:
答案 0 :(得分:1)
在https://docs.gitlab.com/ee/api/branches.html#protect-repository-branch处有一个指向页面https://docs.gitlab.com/ee/api/protected_branches.html的链接,该页面专用于API调用,用于列出受保护的分支,保护和取消保护它们。
要保护分支呼叫POST /projects/:id/protected_branches
。例如
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'