我尝试使用 GitLab API 创建一个新项目。这有效,但这是在我的用户空间中:
curl \
--header "Authorization: Bearer ${GITLAB_API_TOKEN}" \
--request POST \
"https://gitlab.com/api/v4/projects/?name=$test-proj"
Run Code Online (Sandbox Code Playgroud)
但我想在具有 group_id <group_id> 的特定组下执行此操作(我在这里将其空白)。我想到的最明智的方法是:
curl \
--header "Authorization: Bearer ${GITLAB_API_TOKEN}" \
--request POST \
"https://gitlab.com/api/v4/groups/<group_id>/projects/?name=test-proj
Run Code Online (Sandbox Code Playgroud)
但这没有用。关于我如何实现这一目标有什么建议吗?
我查阅了以下参考资料
GitLab 文档提到了pathornamespace_id属性(尽管我实际上是在寻找属性group_id)。我不确定path以及如何指定这一点。我尝试 - 但没有成功 - 检索namespace_idvia
curl --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" "https://gitlab.example.com/api/v4/namespaces"
Run Code Online (Sandbox Code Playgroud)
我很可能无权执行所需的操作。因此,参考官方(GitLab)文档以及有效的测试curl命令将对我非常有帮助 - 谢谢!
mda*_*lah 11
对于任何寻找直接命令的人:
步骤1:
按如下方式导航并从 GUI 中识别组 ID:
管理区域 -> 群组 -> 群组名称
第2步:
使用两个参数构造命令,即name、namespace_id
curl --header "PRIVATE-TOKEN: <myprivatetoken>" -X POST "https://gitlab.com/api/v4/projects?name=myexpectedrepo&namespace_id=38"
Run Code Online (Sandbox Code Playgroud)
就 Gitlab API 而言,用户和组都被视为“命名空间”,因此您可以在字段中使用组 ID 或用户名namespace_id。您可以通过获取带有组 ID(您可以在/groupsAPI 调用中或从组的“个人资料”页面中看到)或用户名的单个命名空间来查看此名称的使用情况:
# this will show the namespace details of the Group with ID 54
curl --header "PRIVATE-TOKEN: ${TOKEN}" "https://gitlab.com/api/v4/namespaces/54
# this will show the namespace details of the User with username my-username
curl --header "PRIVATE-TOKEN: ${TOKEN}" "https://gitlab.com/api/v4/namespace/my-username
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11938 次 |
| 最近记录: |