diff options
author | Rémy Coutable <remy@rymai.me> | 2017-02-22 12:51:31 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-02-22 12:51:31 +0000 |
commit | 90eb2b92a05e7b2c24f68c9a6b9fed7d9e0945dd (patch) | |
tree | 33bcc7d04c17abba2fdc6b1dab18cada50331d38 /doc/ci | |
parent | 87411889b9c8a778bebafeaa381e1d736af7329a (diff) | |
parent | 0b2fc0557f00753a552600da6e5c13d5617afaee (diff) | |
download | gitlab-ce-90eb2b92a05e7b2c24f68c9a6b9fed7d9e0945dd.tar.gz |
Merge branch 'dev-docs-ci_docker_build-example_variable_use' into 'master'
docs(ci/docker_build): Add example of variable use
See merge request !9159
Diffstat (limited to 'doc/ci')
-rw-r--r-- | doc/ci/docker/using_docker_build.md | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/ci/docker/using_docker_build.md b/doc/ci/docker/using_docker_build.md index 2b3082acd5d..8620984d40d 100644 --- a/doc/ci/docker/using_docker_build.md +++ b/doc/ci/docker/using_docker_build.md @@ -308,6 +308,30 @@ push to the Registry connected to your project. Its password is provided in the `$CI_BUILD_TOKEN` variable. This allows you to automate building and deployment of your Docker images. +You can also make use of [other variables](../variables/README.md) to avoid hardcoding: + +```yaml +services: + - docker:dind + +variables: + IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME + +before_script: + - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY + +build: + stage: build + script: + - docker build -t $IMAGE_TAG . + - docker push $IMAGE_TAG +``` + +Here, `$CI_REGISTRY_IMAGE` would be resolved to the address of the registry tied +to this project, and `$CI_BUILD_REF_NAME` would be resolved to the branch or +tag name for this particular job. We also declare our own variable, `$IMAGE_TAG`, +combining the two to save us some typing in the `script` section. + Here's a more elaborate example that splits up the tasks into 4 pipeline stages, including two tests that run in parallel. The `build` is stored in the container registry and used by subsequent stages, downloading the image |