cli使用gitlab project id从gitlab api v4获取管道统计信息
gitlab-stats的Python项目详细描述
转到Gitlab API并基于管道生成报告 建立。为过去两周的管道创建报告。(开) 假设每两周推送次数少于100次)
安装
通过PIP安装,使用:
pip install gitlab_stats
使用pip3进行本地安装:
pip3 install -e .
为了让它工作:
- 使用访问令牌创建一个GITLAB_TOKENenv变量。
获取项目ID
要使脚本工作,您需要获取 Gitlab项目。它是gitlab rest api用来 存储项目信息。
把它放进去 [your project] > Settings > General > General project settings
常规项目设置
如何使用
安装后,您应该可以这样运行:
gitlab_stats <id> -u <your gitlab url> -p <your proxy>
当gitlab_stats -h:
usage: gitlab_stats [-h][-r][-u URL][-p PROXY] id gitlab_stats: Generate a report from gitlab's pipeline metrics positional arguments: id Put the id of the gitlab project optional arguments: -h, --help show this help message and exit -r, --report Generate a csv report -u URL, --url URL Put the url of your gitlab instance if different from https://gitlab.com -p PROXY, --proxy PROXY Add the url of your proxy like 'http://my.proxy.url:8083'
可以使用HTTP_PROXY或gitlab url保存代理 GITLAB_URL。
码头工人
要构建Docker,请使用:
docker build -t gitlab_stats . --build-arg token="your token" --build-arg proxy="your proxy" --build-arg gitlab="gitlab url"
要运行Docker,请使用:
# Having set the token, the proxy and the url when building it: docker run -it exec gitlab_stats bash gitlab_stats project_id
重要提示:
需要将访问令牌设置为环境变量才能访问 你的gitlab。
若要基于您的个人凭据获取访问令牌,请转到 gitlab服务器[Account] -> [Settings] -> [Access Tokens]
常规项目设置
然后给它命名并单击Create personal access token。
将此令牌保存在安全的地方,然后保存在bash中:
exportGITLAB_TOKEN=<token>