以编程方式锁定GitLab分支

时间:2019-03-13 09:38:01

标签: git jenkins gitlab jenkins-plugins

背景: 我们希望在部署Jenkins作业运行时锁定分支以进行合并

问题: 有没有办法以编程方式锁定GitLab分支?
例如在GitLab受保护的分支上设置“ maintainers_can_push”:false”

到目前为止已检查:

  1. GitLab上未发现任何有关此类功能的提及 插入。
  2. GitLab branches API page上找不到任何内容

1 个答案:

答案 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'