GitLab 相关 API 使用
DevOps 代码发布需要获取仓库的相关信息,故用到 gitlab 相关 api
- 获取 api 使用的 access_token
到gitlab上的个人设置中可获取
-
获取仓库信息
curl --header "PRIVATE-TOKEN: xxxxx" https://git.xxx.com/api/v4/projects
search=xxx
参数支对仓库名进行搜索simple=true
参数可以简化返回字段字
保存仓库地址和仓库 id -
获取仓库分支
curl --header "PRIVATE-TOKEN: xxxx" https://git.xxx.com/api/v4/projects/:id/repository/branches
将 ":id" 替换为具体的仓库 id 的值 -
获取仓库标签
curl --header "PRIVATE-TOKEN: xxxx" https://git.xxx.com/api/v4/projects/:id/repository/tags
楼主主要用到这几个接口,其实是发布代码要选择仓库分支或标签,使用命令行获取会出现超时的问题,只能改用api方式获取
具体 api 使用参考gitlab 上的help,https://git.xxxx.com/help/api/README.md
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: