REST API可一次在gitlab中创建多个组

时间:2019-05-08 14:06:30

标签: gitlab-api gitlab-ee

我已经安装了GitLab EE(11.4.7-ee)。我正在尝试使用REST API创建mulitplr组。

https://testserver/gitlab/api/v4/groups

发布数据:

[
    { "name": "test1", "path": "test1" },
    { "name": "test2", "path": "test2" },
    { "name": "test3", "path": "test3" }
    ]

错误消息:

  

{“错误”:“名称丢失,路径丢失”}

如何在一个GitLab Group中创建多个组Group create Rest API

1 个答案:

答案 0 :(得分:2)

我已经编写了python脚本以在gitlab中创建多个组

import requests
import json
import urllib3

with open('./jfmjson.json', 'r') as f:
    jfm_dict = json.load(f)

for jfm in jfm_dict:
    print(jfm['path'])
    gitlab_url = "https://testserver/gitlab/api/v4/groups"
    headers = {'Content-type': 'application/json', 'PRIVATE-TOKEN': 'pxpR3sehJ-xYzz61XxAs'}
    data = {'name': jfm['path'], 'path': jfm['path'], 'description': jfm['name']}
    urllib3.disable_warnings()
    r = requests.post(gitlab_url, data=json.dumps(data), headers=headers, verify=False)