113

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 git and build-essentials (now named precise:base) I got the following .gitlab-ci.yml running:

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.

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
M.K. aka Grisu
  • 2,338
  • 5
  • 17
  • 32

2 Answers2

156

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
phoenix
  • 7,988
  • 6
  • 39
  • 45
Yong Jie Wong
  • 2,121
  • 2
  • 15
  • 16
  • 19
    is there a way to define two images per job? I need a gradle:jdk11 image as well as a mysql image for a particular testing job – Hemil Feb 29 '20 at 12:10
  • @Hemil did you get a way to use 2 images ? – bucky barns May 31 '21 at 13:15
  • @buckybarns there is a way to use services in gitlab. So I can use one image for jdk add specify a service for mysql. Unfortunately, I have abandoned that project but you can find resources on how to add services in gitlab – Hemil Jun 01 '21 at 15:46
  • @Hemil i used a custom gitlab runner instead. Since I had a lot of configurations to be added on gitlab runner. – bucky barns Jun 02 '21 at 11:32
50

Your can use Anchors to make the .gitlab-ci.yml more clearly. (But this need GitLab 8.6 and 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
Jintao Zhang
  • 778
  • 5
  • 9