4

当我在作业日志中使用 gitlab 和 docker 时,我可以获得以下信息:

Running with gitlab-ci-multi-runner 9.5.0 (413da38)
  on platform-docker-orc (2c06225e)
Using Docker executor with image registry:5000/local_image: ...
Using docker image sha256:db4434f2a9c3529af30397031df5bc1277f13882e0f6613a8c8f9c059645c04d for predefined container...
Pulling docker image registry:5000/local_image ...
Using docker image registry:5000/local_image ID=sha256:8d1cac8ae6371b01505e9cd3aaf654696cc144117a9c89dcd21cf4c0d9cfa709 for build container...
Running on runner-2c06225e-project-99-concurrent-0 via a96c0c765ce7...

如何获取执行 gitlab 作业的容器 ID?

4

1 回答 1

5

您可以通过利用容器上的标签来获取容器 ID:

docker ps -q -f "label=com.gitlab.gitlab-runner.job.id=$CI_JOB_ID" -f "label=com.gitlab.gitlab-runner.type=build"

指定label=com.gitlab.gitlab-runner.type=build过滤器会将其限制在构建容器中。否则,您还将获得定义为您工作的一部分的服务容器。

于 2018-03-21T12:42:19.643 回答