将变量从gitlab-ci.yml传递给Dockerfile而不使用docker build

时间:2019-09-11 11:05:48

标签: docker continuous-integration gitlab

我是Docker的新手,我想将gitlab-ci变量传递给Dockerfile。尝试了很多东西,但没有任何效果。以下是我的gitlab-ci.yml

     api-tests:
  image: test-img
  stage: test
  services:
    - docker:abc
  variables:
    privileged: "true"
    DOCKER_HOST: tcp://localhost:2375
  script:
    - apk add dialog && apk add bind-tools
    - docker login -u $ci_account -p $ci_token $REGISTRY_HOST
    - git clone --single-branch --depth 1 --recurse-submodules --branch master ssh://git@git.easygroup.co:1234/test/code.git test && cd test
    - cd -
    - make test-project
    - TEST_PATH=first make test; r=$?
  after_script:
    - docker ps -a
    - docker logs --tail=50 test-project

谢谢

1 个答案:

答案 0 :(得分:0)

您需要使用.gitlab-ci.yml变量部分创建环境变量。一旦创建了环境变量,便可以通过脚本或其他过程进行访问。

Git实验室文档:

Creating a custom environment variable
Assume you have something you want to repeat through your scripts in GitLab CI/CD’s configuration file. To keep this example simple, let’s say you want to output HELLO WORLD for a TEST variable.

You can either set the variable directly in the .gitlab-ci.yml file or through the UI.

Via .gitlab-ci.yml
To create a new custom env_var variable via .gitlab-ci.yml, define their variable/value pair under variables:

variables:
  TEST: "HELLO WORLD"

For a deeper look into them, see .gitlab-ci.yml defined variables.

更多信息在这里-> https://docs.gitlab.com/ee/ci/variables/#gitlab-ciyml-defined-variables