Incorrect number of jobs

Following the docs for Multiple Variables per Item I have defined the following travis file:

sudo: required

language: node_js
node_js:
  - 10

services:
  - docker

env:
  - DOCKER_MYSQL_TAG=5 DOCKER_MARIADB_TAG=10.4.12 DOCKER_POSTGRES_TAG=10 DOCKER_MSSQL_TAG=2017-CU17-ubuntu
  - DOCKER_MYSQL_TAG=8 DOCKER_MARIADB_TAG=10.4.12 DOCKER_POSTGRES_TAG=11 DOCKER_MSSQL_TAG=2019-latest

install:
  - npm install

jobs:
  include:
    - stage: test
      script: npm run test
    - stage: build
      script: npm run build
    - stage: deploy
      script: npm run build
      deploy:
        edge: true
        provider: npm
        email: $NPM_EMAIL
        api_key: $NPM_TOKEN
        on:
          branch: master

stages:
  - test
  - build
  - deploy

I expected 2 builds but this triggers 3 builds for the test stage. What could be the reason?

You are getting 2 jobs from matrix expansion, in the default test stage, accompanied by 3 manually defined ones, in the specified stages.


One of the 3 jobs in jobs.include has the stage attribute set to test, so it is combined with the 2 jobs at the top level, which also belong to the default test stage. Everything is working as documented.

Hi, thanks for the answer!

I still don’t understand probably the matrix expansion feature, but from the travis page I got the following:

So for the test stage it ran with 3 environments. What i want instead is to run the test stage only with 2 environments and build/deploy stage with only 1 environment (as it did). How should I change the travis file to achieve this behaviour?

Please read “Build Stages” document @native-api pointed to earlier in this topic. If you only want 2 jobs with differing set of environment variables, you need to drop the first job in jobs.include, and define script at the top level.

â‹®
env:
  - DOCKER_MYSQL_TAG=5 DOCKER_MARIADB_TAG=10.4.12 DOCKER_POSTGRES_TAG=10 DOCKER_MSSQL_TAG=2017-CU17-ubuntu
  - DOCKER_MYSQL_TAG=8 DOCKER_MARIADB_TAG=10.4.12 DOCKER_POSTGRES_TAG=11 DOCKER_MSSQL_TAG=2019-latest

install:
  - npm install
script: npm run test

jobs:
  include:
    - stage: build
      script: npm run build
    - stage: deploy
      script: npm run build
      deploy:
        edge: true
        provider: npm
        email: $NPM_EMAIL
        api_key: $NPM_TOKEN
        on:
          branch: master

stages:
  - test
  - build
  - deploy
1 Like

Thanks!