获取执行gitlab作业的容器ID

时间:2017-09-27 15:10:29

标签: gitlab-ci-runner gitlab-ce

当我在作业日志中使用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?

1 个答案:

答案 0 :(得分:2)

您可以通过利用容器上的标签来获取容器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过滤器会将其限制为构建容器。此外,您还将获得服务容器定义为您工作的一部分。