在 Gitlab CI 中使用 docker 图像时,如何引用服务的别名
When using docker images in Gitlab CI, how do I deference the alias of a service
下面是我的 gitlab-ci.yml 文件的摘录。简单地说我需要创建一个redis服务,然后在测试需要时引用它。
因为 redis 服务器是动态创建的,所以我不知道有什么简单的方法可以告诉它查看 'localhost' 或 123.321.234.234 等
有没有办法引用服务的别名,例如下面创建的别名,以便可以将其值传递到另一个容器中,这样它们就可以 'talk'?在我的代码中,我试图引用 'redis' 别名,并在管道期间将该值提供给环境变量,但它变成了文字字符串。
我也试过 ${redis} 但同样失败了。
我得到的最深入的是我从关于 Anchors 的 gitlab 文档中读到的内容,我在下面有。
以下是我寻找答案的地方
https://docs.gitlab.com/ce/ci/yaml/README.html
https://docs.gitlab.com/ee/ci/docker/using_docker_images.html
# the image and gitlab services to use in the build stages
.build-web-image: &build-web-image
image: Dontworryaboutit.com:4567/folder/dockerImage:1.0.0
services:
- name: redis:3.2.8
alias: redis
# The job that runs the yarn run test that requires a redis server
Test Web:
<<: *build-web-image
stage: Stage 2
before_script:
- export REDIS=redis:1234
- yarn
script:
- yarn run test
别名可以通过引用它们的字符串名称来取消引用,没有像
这样的额外装饰
${variable}
你可以直接输入
variable
确保检查您的 config.toml 文件以确保 docker 执行器被用于该运行器。切换 CI/CD 策略时很容易犯错误。
下面是我的 gitlab-ci.yml 文件的摘录。简单地说我需要创建一个redis服务,然后在测试需要时引用它。
因为 redis 服务器是动态创建的,所以我不知道有什么简单的方法可以告诉它查看 'localhost' 或 123.321.234.234 等
有没有办法引用服务的别名,例如下面创建的别名,以便可以将其值传递到另一个容器中,这样它们就可以 'talk'?在我的代码中,我试图引用 'redis' 别名,并在管道期间将该值提供给环境变量,但它变成了文字字符串。
我也试过 ${redis} 但同样失败了。
我得到的最深入的是我从关于 Anchors 的 gitlab 文档中读到的内容,我在下面有。
以下是我寻找答案的地方
https://docs.gitlab.com/ce/ci/yaml/README.html https://docs.gitlab.com/ee/ci/docker/using_docker_images.html
# the image and gitlab services to use in the build stages
.build-web-image: &build-web-image
image: Dontworryaboutit.com:4567/folder/dockerImage:1.0.0
services:
- name: redis:3.2.8
alias: redis
# The job that runs the yarn run test that requires a redis server
Test Web:
<<: *build-web-image
stage: Stage 2
before_script:
- export REDIS=redis:1234
- yarn
script:
- yarn run test
别名可以通过引用它们的字符串名称来取消引用,没有像
这样的额外装饰${variable}
你可以直接输入
variable
确保检查您的 config.toml 文件以确保 docker 执行器被用于该运行器。切换 CI/CD 策略时很容易犯错误。