Skip to main content

CLI to get pipeline stats from gitlab API v4 using gitlab project ID

Project description

Github PyPI version Gitlab Python Build Status codecov Codacy Badge

Get to the gitlab API and generates a report based on the pipeline builds. Creates a report for the pipelines of the last two weeks. (On the assumption that there are less than 100 push per 2 weeks)

Installation

Install via pip using:

pip install gitlab_stats

Local install with pip3:

pip3 install -e .

In order to make it work:

  • Create a GITLAB_TOKEN env variable with your access token.

Get the project ID

For the script to work, you will need to get the project ID of your gitlab project. It is a unique ID that is used by the gitlab REST API to store your project information.

Get it in [your project] > Settings > General > General project settings

General project settings

General project settings

How to use

When installed you should be able to run it like that:

gitlab_stats <id> -u <your gitlab url> -p <your proxy>

Here is the help when 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'

You can save proxy with HTTP_PROXY or gitlab url with GITLAB_URL.

Docker

To build the docker use:

docker build -t gitlab_stats . --build-arg token="your token" --build-arg proxy="your proxy" --build-arg gitlab="gitlab url"

To run the docker use:

# Having set the token, the proxy and the url when building it:
docker run -it exec gitlab_stats bash gitlab_stats project_id

Important Note:

You will need an access token set up as an environment variable to reach your gitlab.

To get an access token based on your personal credentials go to your gitlab server [Account] -> [Settings] -> [Access Tokens]

General project settings

General project settings

Then give it a name and click Create personal access token.

Save this token somewhere safe then in bash:

export GITLAB_TOKEN=<token>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gitlab-stats, version 1.2.1
Filename, size File type Python version Upload date Hashes
Filename, size gitlab_stats-1.2.1-py3-none-any.whl (43.8 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size gitlab_stats-1.2.1.tar.gz (22.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page