Travis similar code for GitLab CI?

I have the following .travis.yml file:

language: node_js
node_js:
  - 10
  - 12
  - 14
  - 16
install:
  - npm install
script:
  - npm run lint && npm run unit-test

and based on this I created the following .gitlab.yml file:

# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/node/tags/
before_script:
  - node -v
  - npm -v
  - npm install

cache:
  paths:
    - node_modules/

# Supported node versions can be found here:
# https://github.com/nodejs/LTS#lts_schedule
Node 10:
  image: node:10
  script:
    - npm run lint && npm run unit-test

Node 12:
  image: node:12
  script:
    - npm run lint && npm run unit-test

Node 14:
  image: node:14
  script:
    - npm run lint && npm run unit-test


Node 16:
  image: node:16
  script:
    - npm run lint && npm run unit-test

Still, I am wondering if there is a more simple way to avoid so many code-duplications?
Also the scripts part can get pretty big.

I’ve hit another problem here, if I want to use something like this from travis:

addons: # get google-chrome [stable|beta]
  chrome: beta
language: node_js

@klodoma Thanks for the post!

The matrix keyword should get you what you’re looking for. Here’s an example from the forum.

-James H, GitLab Product Manager, Verify:Testing

1 Like

Thank you. It seems to be working.

Here is my gitlab-ci.yml file, maybe it helps someone:


image: ubuntu:20.04

before_script:
  - export DEBIAN_FRONTEND=noninteractive
  - apt-get update
  - apt-get install curl wget -y
  - wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
  - apt-get install ./google-chrome-stable_current_amd64.deb  -y
  - curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
  - . ~/.nvm/nvm.sh
  - nvm --version
  - nvm install $NODEJS
  - node -v
  - npm -v
  - npm install

tests:
  script:
    - npm run lint && npm run unit-test
    - npm run sanity-test
    - npm run smoke-test
  parallel:
    matrix:
      - NODEJS:
          - 10
          - 12
          - 14
          - 16
3 Likes