git .gitlab-ci.yml 中的多个 Docker 镜像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33387622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:39:59  来源:igfitidea点击:

Multiple Docker images in .gitlab-ci.yml

gitdockercontinuous-integrationgitlab-ci

提问by M.K. aka Grisu

Here is my problem setup with GitLab and its integrated CI service. I have a current GitLab 8.1. and a gitlabci-multi-runner (0.6.2) with Docker support. After extending the ubuntu:precise image to include gitand build-essentials(now named precise:base) I got the following .gitlab-ci.ymlrunning:

这是我对 GitLab 及其集成 CI 服务的问题设置。我有一个当前的 GitLab 8.1。以及一个支持 Docker 的 gitlabci-multi-runner (0.6.2)。在扩展 ubuntu:precise 图像以包含gitbuild-essentials(现在命名为precision:base)后,我得到了以下.gitlab-ci.yml运行:

image: precise:base
before_script:
   - apt-get install --yes cmake libmatio-dev libblas-dev libsqlite3-dev libcurl4-openssl-dev
   - apt-get install --yes libarchive-dev liblzma-dev

build:
  script:
    - mkdir build/
    - cd build
    - cmake -D CMAKE_BUILD_TYPE=Debug ../
    - make

Now my question is how to include more jobs on different images? Because I need to check if the code compiles (and later on works) on different operating systems like Ubuntu Precise, Ubuntu Trusty, CentOS 6, CentOS 7. To reduce the work I think the best way is to provide different Docker images as base.

现在我的问题是如何在不同的图像上包含更多的工作?因为我需要检查代码是否可以在不同的操作系统上编译(以及稍后的工作),比如 Ubuntu Precise、Ubuntu Trusty、CentOS 6、CentOS 7。为了减少工作,我认为最好的方法是提供不同的 Docker 镜像作为基础。

Now the questions is how must the .gitlab-ci.ymllook like to support this?

现在的问题是如何.gitlab-ci.yml支持这一点?

回答by yjwong

You can define the image to use per job.

您可以定义每个作业要使用的图像

For instance:

例如:

before_script:
   - apt-get install --yes cmake libmatio-dev libblas-dev libsqlite3-dev libcurl4-openssl-dev
   - apt-get install --yes libarchive-dev liblzma-dev

build:precise:
  image: precise:base
  script:
    - mkdir build/
    - cd build
    - cmake -D CMAKE_BUILD_TYPE=Debug ../
    - make

build:trusty:
  image: trusty:base
  script:
    - mkdir build/
    - cd build
    - cmake -D CMAKE_BUILD_TYPE=Debug ../
    - make

回答by Jintao Zhang

Your can use Anchorsto make the .gitlab-ci.ymlmore clearly. (But this need GitLab 8.6 and GitLab Runner v1.1.1.)

您可以使用Anchors使.gitlab-ci.yml更清楚。(但这需要 GitLab 8.6 和 GitLab Runner v1.1.1。)

Like this:

像这样:

before_script:
   - apt-get install --yes cmake libmatio-dev libblas-dev libsqlite3-dev libcurl4-openssl-dev
   - apt-get install --yes libarchive-dev liblzma-dev

.build_template: &build_definition
  script:
    - mkdir build/
    - cd build
    - cmake -D CMAKE_BUILD_TYPE=Debug ../
    - make

build:precise:
  image: precise:base
  <<: *build_definition

build:trusty:
  image: trusty:base
  <<: *build_definition