# Incorrect number of jobs

**URL:** <https://travis-ci.community/t/incorrect-number-of-jobs/7268>\
**Category:** Travis CI Discussions & Feedback\
**Tags:** build-env, travis-build\
**Created:** [February 18, 2020, 11:38pm UTC](https://travis-ci.community/t/incorrect-number-of-jobs/7268 "2020-02-18T23:38:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![spinlud](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/spinlud/32/3850_2.png) [@spinlud](https://travis-ci.community/u/spinlud)\
**Post date:** [February 18, 2020, 11:38pm UTC](https://travis-ci.community/t/incorrect-number-of-jobs/7268/1 "2020-02-18T23:38:49Z")

</div>

Following the [docs](https://docs.travis-ci.com/user/environment-variables/) for `Multiple Variables per Item` I have defined the following travis file:

```auto
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](https://travis-ci.org/spinlud/sequelize-typescript-generator/builds/652234180). What could be the reason?

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [February 19, 2020, 12:20am UTC](https://travis-ci.community/t/incorrect-number-of-jobs/7268/2 "2020-02-19T00:20:03Z")

</div>

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

> **[Travis CI Documentation](https://docs.travis-ci.com/user/build-matrix/)**
>
> Build Matrix

  

> **[Travis CI Documentation](https://docs.travis-ci.com/user/build-stages/)**
>
> Build Stages

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [February 19, 2020, 2:02am UTC](https://travis-ci.community/t/incorrect-number-of-jobs/7268/3 "2020-02-19T02:02:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![spinlud](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/spinlud/32/3850_2.png) [@spinlud](https://travis-ci.community/u/spinlud)\
**Post date:** [February 19, 2020, 8:58am UTC](https://travis-ci.community/t/incorrect-number-of-jobs/7268/4 "2020-02-19T08:58:15Z")

</div>

Hi, thanks for the answer!

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/travis_ci/original/2X/6/61fd6c52df05236abc108a662e3ea82e2b5afe51.png)

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?

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [February 19, 2020, 1:07pm UTC](https://travis-ci.community/t/incorrect-number-of-jobs/7268/5 "2020-02-19T13:07:10Z")

</div>

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.

```auto
⋮
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

```

---

<div class="post-metadata">

**Author:** ![spinlud](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/spinlud/32/3850_2.png) [@spinlud](https://travis-ci.community/u/spinlud)\
**Post date:** [February 19, 2020, 9:00pm UTC](https://travis-ci.community/t/incorrect-number-of-jobs/7268/6 "2020-02-19T21:00:33Z")

</div>

Thanks!
