跳转到主要内容

从命令行查看GitLab CI流水线结果

项目描述

https://github.com/mgedmin/gitlab-trace/workflows/build/badge.svg?branch=master https://coveralls.io/repos/mgedmin/gitlab-trace/badge.svg?branch=master

有时我想从我的终端查看GitLab CI构建状态

$ gitlab-trace
GitLab project: Foretagsdeklaration/foretagsdeklaration
Available jobs for pipeline #84214:
   --job=500786 - success - build_server
   --job=500787 - success - build_client
   --job=500788 - success - test_safety
   --job=500789 - success - test_dev_safety
   --job=500790 - success - test_bandit
   --job=500791 - success - test_crontabs
   --job=500792 - success - test_newrelic
   --job=500793 - success - unittests_server
   --job=500794 - success - unittests_client
   --job=500795 - success - build_docker_image
   --job=500796 - failed - test_robot
   --job=500797 - success - test_robot_bolfin

通过传递作业ID,您可以更详细地查看失败的作业

$ gitlab-trace --job=500796
...
Uploading artifacts...
robottests/output: found 540 matching files
Uploading artifacts to coordinator... ok            id=500796 responseStatus=201 Created token=6yaRqQPr
ERROR: Job failed: exit code 1

您可以在作业运行时观看作业

$ gitlab-trace --job=500796 --tail --follow
...
Uploading artifacts...
robottests/output: found 540 matching files
Uploading artifacts to coordinator... ok            id=500796 responseStatus=201 Created token=6yaRqQPr
ERROR: Job failed: exit code 1

您可以看到正在运行的作业

$ gitlab-trace --running --tail --follow
...
Uploading artifacts...
robottests/output: found 540 matching files
Uploading artifacts to coordinator... ok            id=500796 responseStatus=201 Created token=6yaRqQPr
ERROR: Job failed: exit code 1

您可以看到不同的分支

$ gitlab-trace --branch=master
GitLab project: Foretagsdeklaration/foretagsdeklaration
https://git.vaultit.org/Foretagsdeklaration/foretagsdeklaration/pipelines/84185
Available jobs for pipeline #84185:
   --job=500692 - success - build_server
   --job=500693 - success - build_client
   --job=500694 - success - test_safety
   --job=500695 - success - test_dev_safety
   --job=500696 - success - test_bandit
   --job=500697 - success - test_crontabs
   --job=500698 - success - test_newrelic
   --job=500699 - success - unittests_server
   --job=500700 - success - unittests_client
   --job=500701 - success - build_docker_image
   --job=500702 - failed - test_robot
   --job=500703 - success - test_robot_bolfin
   --job=500704 - success - tag_docker_image
   --job=500705 - manual - deploy_stv_managedkube_alpha
   --job=500706 - manual - deploy_id06_alpha
   --job=500707 - manual - deploy_id06_alpha_fs31
   --job=500708 - manual - deploy_id06_beta
   --job=500709 - manual - deploy_id06_beta_fs31
   --job=500710 - manual - deploy_stv_alpha
   --job=500747 - success - test_robot

您可以看到第N个最新流水线

$ gitlab-trace -1   # the latest one, default when run with no arguments

$ gitlab-trace -2   # the one before that

$ gitlab-trace --branch=mybranch -1   # the last one on this branch

您可以通过ID查看特定的流水线

$ gitlab-trace 84185

您可以在该流水线中查看特定的作业

$ gitlab-trace 84185 test_robot

如果作业已经重试多次,您可以通过ID查看特定的运行

$ gitlab-trace 84185 test_robot 1

$ gitlab-trace 84185 test_robot 2

安装

pip3 install --user gitlab-trace 应该处理一切,只需确保 ~/.local/bin 在您的 $PATH 中。

或者您可能想使用脚本安装程序,如 pipx(我最喜欢的)。

配置

创建一个 ~/.python-gitlab.cfg,如下所示

[global]
default = mygitlab

[mygitlab]
url = https://gitlab.example.com/
private_token = ...

您可以在GitLab配置文件设置中创建一个私有访问令牌。它需要“read_api”访问范围。

用法

通过以下方式提供帮助

$ gitlab-trace --help
usage: gitlab-trace [-h] [--version] [-v] [--debug] [-g NAME] [-p ID]
                    [--job ID] [--running] [-b NAME] [-t [N]] [-f]
                    [--print-url] [-a]
                    [PIPELINE-ID] [JOB-NAME] [NTH-JOB-OF-THAT-NAME]

gitlab-trace: show the status/trace of a GitLab CI pipeline/job.

positional arguments:
  PIPELINE-ID           select a GitLab CI pipeline by ID (default: the last
                        pipeline of a git branch)
  JOB-NAME              select a GitLab CI pipeline job by name
  NTH-JOB-OF-THAT-NAME  select n-th GitLab CI pipeline job by this name
                        (default: the last one)

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -v, --verbose         print more information
  --debug               print even more information, for debugging
  -g NAME, --gitlab NAME
                        select configuration section in ~/.python-gitlab.cfg
  -p ID, --project ID   select GitLab project ('group/project' or the numeric
                        ID)
  --job ID              show the trace of GitLab CI job with this ID
  --running             show the trace of the currently running GitLab CI job,
                        if there is one (if there's more than one, picks the
                        first one)
  -b NAME, --branch NAME, --ref NAME
                        show the last pipeline of this git branch (default:
                        the currently checked out branch)
  -t [N], --tail [N]    show the last N lines of the trace log
  -f, --follow          periodically poll and output additional logs as the
                        job runs
  --print-url, --print-uri
                        print URL to job page on GitLab instead of printing
                        job's log
  -a, --artifacts       download build artifacts

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

gitlab-trace-0.7.1.tar.gz (27.6 kB 查看散列值)

上传时间

构建分布

gitlab_trace-0.7.1-py3-none-any.whl (19.4 kB 查看散列值)

上传时间 Python 3

由以下支持