# Jobs / matrix include are ignored if env is customized

**URL:** <https://travis-ci.community/t/jobs-matrix-include-are-ignored-if-env-is-customized/6313>\
**Category:** Travis CI Discussions & Feedback\
**Tags:** stages, bug, build-stages, build-matrix\
**Created:** [December 5, 2019, 8:56pm UTC](https://travis-ci.community/t/jobs-matrix-include-are-ignored-if-env-is-customized/6313 "2019-12-05T20:56:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanySK](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/danysk/32/1399_2.png) [@DanySK](https://travis-ci.community/u/DanySK)\
**Post date:** [December 5, 2019, 8:56pm UTC](https://travis-ci.community/t/jobs-matrix-include-are-ignored-if-env-is-customized/6313/1 "2019-12-05T20:56:59Z")

</div>

I am very puzzled. I always use stages and matrix expansion with success. Now, I copied a working configuration, and it seems that matrix.include (or jobs.include) is ignores all jobs for which I customize `env`.  
If I remove `env` customization, everything works as intended.

Any suggestions? See e.g. [this build](https://travis-ci.org/DanySK/conrec/builds/621308241): only the included job with no customized env gets launched.

I can’t wrap my head around this behaviour, I use the same strategy elsewhere and it always worked.

---

<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:** [December 5, 2019, 10:07pm UTC](https://travis-ci.community/t/jobs-matrix-include-are-ignored-if-env-is-customized/6313/2 "2019-12-05T22:07:40Z")

</div>

Hmmm. What is [`env.jobs` key](https://travis-ci.com/travis-ci/s3-gcs-transporter/builds/139610794) supposed to do? Maybe I missed a memo, but this key might be interfering with the top-level `jobs` key (presumably via config validation). This could be a bug in our validator, and if so, it should be fixed. It would be instructive to know if turning off the config validation eradicates the problem.

---

<div class="post-metadata">

**Author:** ![DanySK](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/danysk/32/1399_2.png) [@DanySK](https://travis-ci.community/u/DanySK)\
**Post date:** [December 5, 2019, 11:05pm UTC](https://travis-ci.community/t/jobs-matrix-include-are-ignored-if-env-is-customized/6313/3 "2019-12-05T23:05:44Z")

</div>

it’s not `env.jobs`, what is not working is the addition of further keys on included jobs:

`jobs.include` is a list, if one element of such list contains `env`, the job does not get scheduled. Otherwise, it does. According to [the documentation](https://docs.travis-ci.com/user/build-matrix/#explicitly-including-jobs), this is supposed to add further keys to the global environment.  
And it does, in every other build I have.

```auto
[...]
jobs:
  exclude:
    - os: *reference_os
      env: *reference_jdk
  include:
    # Not scheduled
    - stage: check
      env: NOTHING=test
      script: echo hello
    # Correctly scheduled
    - stage: check
      script: echo hello

```

Build validation shows two warnings:  
[  
 `root` : deprecated key `reference_os` (anchor on a non-private key)  
 ](https://travis-ci.org/DanySK/conrec/builds/621308241/config#rccb_conrec:.travis.yml@ebdbaf7db93e0a32.3)

[  
 `root` : deprecated key `reference_jdk` (anchor on a non-private key)  
 ](https://travis-ci.org/DanySK/conrec/builds/621308241/config#rccb_conrec:.travis.yml@ebdbaf7db93e0a32.1)

---

<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:** [December 6, 2019, 2:04am UTC](https://travis-ci.community/t/jobs-matrix-include-are-ignored-if-env-is-customized/6313/4 "2019-12-06T02:04:05Z")

</div>

> [@DanySK](#):
>
> it’s not `env.jobs` , what is not working is the addition of further keys on included jobs:

Not necessarily. It is possible that `env.jobs` _replaces_ what is in `jobs.include`.

Here’s the build _with_ config validation [Travis CI - Test and Deploy with Confidence](https://travis-ci.org/BanzaiMan/travis_production_test/builds/621408898)  
and here’s one without: [Travis CI - Test and Deploy with Confidence](https://travis-ci.org/BanzaiMan/travis_production_test/builds/621408791)

and here’s the same configuration, but without `env.jobs`, and config validation: [Travis CI - Test and Deploy with Confidence](https://travis-ci.org/BanzaiMan/travis_production_test/builds/621409292)

---

<div class="post-metadata">

**Author:** ![DanySK](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/danysk/32/1399_2.png) [@DanySK](https://travis-ci.community/u/DanySK)\
**Post date:** [December 6, 2019, 9:05am UTC](https://travis-ci.community/t/jobs-matrix-include-are-ignored-if-env-is-customized/6313/5 "2019-12-06T09:05:30Z")

</div>

@BanzaiMan I see. I also detected a different behaviour in `jobs.exclude`. It used to exclude only jobs defined in `env.jobs`, now it also excludes jobs defined in `jobs.include`. This sounds consistent with the issue you supposed, if I correctly understood what you meant.

What is the expected behaviour?  
I would suggest to separate matrix expansion and `root.jobs`. At least for my use cases, what I usually do is:

- Prepare a test matrix using env.jobs and matrix expansion
- use jobs.include to add additional behaviour, e.g. an initial check in a previous stage to prevent multiplatform testing if a reference platform fails (reducing resource usage and build times), or a further stage for deployment after success
- use jobs.exclude to filter out _matrix_ jobs that are not necessary – but I do not want to also match jobs in `jobs.include`, as I included them manually.
