一 背景介绍

  • repo库迁移及批量创建gitlab项目

二 软件版本

[root@gitlab ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
10.5.5

三 创建group

3.1 官方文件

3.2 查询group

  • 默认返回20个结果,超过20条需要指定per_page

点击查看代码

[root@gitlab ~]# curl --header "PRIVATE-TOKEN: <your_access_token>" "http://gitlab.example.com/api/v4/groups?per_page=100"
{
"id": 121,
"name": "hardware_android7",
"path": "hardware_android7",
"description": "",
"visibility": "private",
"lfs_enabled": true,
"avatar_url": null,
"web_url": "http://gitlab.example.com/groups/hardware_android7",
"request_access_enabled": false,
"full_name": "hardware_android7",
"full_path": "hardware_android7",
"parent_id": null
},

3.3 查询subgroup

  • id  #组的id
  • 默认返回20条结果,超过20条需要指定per_page
[root@gitlab ~]# curl --header "PRIVATE-TOKEN: <your_access_token>" "http://gitlab.example.com/api/v4/groups/:id/subgroups"

3.4 查询组下的项目

  • id  #组的id
  • 默认返回20条结果,超过20条需要指定per_page
[root@gitlab ~]# curl --header "PRIVATE-TOKEN: <your_access_token>" "http://gitlab.example.com/api/v4/groups/:id/projects"

3.5 创建group

3.5.1 创建group

  • path   #组路径
  • name  #组名字

点击查看代码

[root@gitlab ~]# curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --header "Content-Type: application/json" --data '{"path": "wgs_android", "name": "wgs_android"}' "http://gitlab.example.com/api/v4/groups/"
{
"id": 124,
"name": "wgs_android",
"path": "wgs_android",
"description": "",
"visibility": "private",
"lfs_enabled": true,
"avatar_url": null,
"web_url": "http://gitlab.example.com/groups/wgs_android",
"request_access_enabled": false,
"full_name": "wgs_android",
"full_path": "wgs_android",
"parent_id": null,
"projects": [],
"shared_projects": []
}

3.5.2 验证创建group

  • id #组id=124

点击查看代码

[root@gitlab ~]# curl --header "PRIVATE-TOKEN: <your_access_token>" "http://gitlab.example.com/api/v4/groups/124"
{
"id": 124,
"name": "wgs_android",
"path": "wgs_android",
"description": "",
"visibility": "private",
"lfs_enabled": true,
"avatar_url": null,
"web_url": "http://gitlab.example.com/groups/wgs_android",
"request_access_enabled": false,
"full_name": "wgs_android",
"full_path": "wgs_android",
"parent_id": null,
"projects": [],
"shared_projects": []
}

3.5.3 创建subgroup

  • path    # 子组路径
  • name  #子组名字
  • parent_id  #父组id

点击查看代码

[root@gitlab ~]# curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --header "Content-Type: application/json" --data '{"path": "android", "name": "android", "parent_id": 121 }' "https://gitlab.example.com/api/v4/groups/"
{
"id": 123,
"name": "android",
"path": "android",
"description": "",
"visibility": "private",
"lfs_enabled": true,
"avatar_url": null,
"web_url": "http://gitlab.example.com/groups/hardware_android7/android",
"request_access_enabled": false,
"full_name": "hardware_android7 / android",
"full_path": "hardware_android7/android",
"parent_id": 121,
"projects": [],
"shared_projects": []
}

3.5.4 验证结果

  • id  #组id=123

点击查看代码

[root@gitlab ~]# curl --header "PRIVATE-TOKEN: <your_access_token>" "http://gitlab.example.com/api/v4/groups/123" 
{
"id": 123,
"name": "android",
"path": "android",
"description": "",
"visibility": "private",
"lfs_enabled": true,
"avatar_url": null,
"web_url": "http://gitlab.example.com/groups/hardware_android7/android",
"request_access_enabled": false,
"full_name": "hardware_android7 / android",
"full_path": "hardware_android7/android",
"parent_id": 121,
"projects": [],
"shared_projects": []
}

四 创建项目

4.1 官方文档

4.2 查询所有项目

[root@gitlab ~]# curl --header "PRIVATE-TOKEN: <your_access_token>" "http://gitlab.example.com/api/v4/projects"

4.3 创建项目

  • name  #项目名称
  • namespace_id  #项目所在组id

点击查看代码

[root@gitlab ~]# curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --data "name=RKDocs&namespace_id=123" http://gitlab.example.com/api/v4/projects
{
"id": 381,
"description": null,
"name": "RKDocs",
"name_with_namespace": "hardware_android7 / android / RKDocs",
"path": "rkdocs",
"path_with_namespace": "hardware_android7/android/rkdocs",
"created_at": "2021-08-30T09:33:34.221Z",
"default_branch": null,
"tag_list": [],
"ssh_url_to_repo": "git@gitlab.example.com:hardware_android7/android/rkdocs.git",
"http_url_to_repo": "http://gitlab.example.com.com/hardware_android7/android/rkdocs.git",
"web_url": "http://gitlab.example.com/hardware_android7/android/rkdocs",
"avatar_url": null,
"star_count": 0,
"forks_count": 0,
"last_activity_at": "2021-08-30T09:33:34.221Z",
"_links": {
"self": "http://gitlab.example.com/api/v4/projects/381",
"issues": "http://gitlab.example.com/api/v4/projects/381/issues",
"merge_requests": "http://gitlab.example.com/api/v4/projects/381/merge_requests",
"repo_branches": "http://gitlab.example.com/api/v4/projects/381/repository/branches",
"labels": "http://gitlab.example.com/api/v4/projects/381/labels",
"events": "http://gitlab.example.com/api/v4/projects/381/events",
"members": "http://gitlab.example.com/api/v4/projects/381/members"
},
"archived": false,
"visibility": "private",
"resolve_outdated_diff_discussions": false,
"container_registry_enabled": true,
"issues_enabled": true,
"merge_requests_enabled": true,
"wiki_enabled": true,
"jobs_enabled": true,
"snippets_enabled": true,
"shared_runners_enabled": true,
"lfs_enabled": true,
"creator_id": 18,
"namespace": {
"id": 123,
"name": "android",
"path": "android",
"kind": "group",
"full_path": "hardware_android7/android",
"parent_id": 121
},
"import_status": "none",
"import_error": null,
"open_issues_count": 0,
"runners_token": "EeugCfZog-5ymjoZGAHQ",
"public_jobs": true,
"ci_config_path": null,
"shared_with_groups": [],
"only_allow_merge_if_pipeline_succeeds": false,
"request_access_enabled": false,
"only_allow_merge_if_all_discussions_are_resolved": false,
"printing_merge_request_link_enabled": true
}

4.4 验证创建项目

  • id  #项目id=381

点击查看代码

[root@gitlab ~]# curl --header "PRIVATE-TOKEN: <your_access_token>" "http://gitlab.example.com.com/api/v4/projects/381"
{
"id": 381,
"description": null,
"name": "RKDocs",
"name_with_namespace": "hardware_android7 / android / RKDocs",
"path": "rkdocs",
"path_with_namespace": "hardware_android7/android/rkdocs",
"created_at": "2021-08-30T09:33:34.221Z",
"default_branch": null,
"tag_list": [],
"ssh_url_to_repo": "git@gitlab.example.com:hardware_android7/android/rkdocs.git",
"http_url_to_repo": "http://gitlab.example.com/hardware_android7/android/rkdocs.git",
"web_url": "http://gitlab.example.com/hardware_android7/android/rkdocs",
"avatar_url": null,
"star_count": 0,
"forks_count": 0,
"last_activity_at": "2021-08-30T09:33:34.221Z",
"_links": {
"self": "http://gitlab.example.com/api/v4/projects/381",
"issues": "http://gitlab.example.com/api/v4/projects/381/issues",
"merge_requests": "http://gitlab.example.com/api/v4/projects/381/merge_requests",
"repo_branches": "http://gitlab.example.com/api/v4/projects/381/repository/branches",
"labels": "http://gitlab.example.com/api/v4/projects/381/labels",
"events": "http://gitlab.example.com/api/v4/projects/381/events",
"members": "http://gitlab.example.com/api/v4/projects/381/members"
},
"archived": false,
"visibility": "private",
"resolve_outdated_diff_discussions": false,
"container_registry_enabled": true,
"issues_enabled": true,
"merge_requests_enabled": true,
"wiki_enabled": true,
"jobs_enabled": true,
"snippets_enabled": true,
"shared_runners_enabled": true,
"lfs_enabled": true,
"creator_id": 18,
"namespace": {
"id": 123,
"name": "android",
"path": "android",
"kind": "group",
"full_path": "hardware_android7/android",
"parent_id": 121
},
"import_status": "none",
"import_error": null,
"open_issues_count": 0,
"runners_token": "EeugCfZog-5ymjoZGAHQ",
"public_jobs": true,
"ci_config_path": null,
"shared_with_groups": [],
"only_allow_merge_if_pipeline_succeeds": false,
"request_access_enabled": false,
"only_allow_merge_if_all_discussions_are_resolved": false,
"printing_merge_request_link_enabled": true,
"permissions": {
"project_access": null,
"group_access": {
"access_level": 50,
"notification_level": 3
}
}
}