# Included env in job repeated when is run in docker

**URL:** <https://travis-ci.community/t/included-env-in-job-repeated-when-is-run-in-docker/2793>\
**Category:** Node.js\
**Created:** [March 26, 2019, 11:44am UTC](https://travis-ci.community/t/included-env-in-job-repeated-when-is-run-in-docker/2793 "2019-03-26T11:44:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![murcraft](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/murcraft/32/2664_2.png) [@murcraft](https://travis-ci.community/u/murcraft)\
**Post date:** [March 26, 2019, 11:44am UTC](https://travis-ci.community/t/included-env-in-job-repeated-when-is-run-in-docker/2793/1 "2019-03-26T11:44:52Z")

</div>

I deploy my tests environment in docker containers. So, I separated deployment into 2 parts: building docker image with all needed environment and running every tests suite in he second job test. Here is my travis file:  
[Travis.yml](http://joxi.ru/V2V81OeTdd33Pr)

Here is build in Travis:  
[https://travis-ci.com/murcraft/ProtractorGoogleTest/builds/105824144](https://travis-ci.com/murcraft/ProtractorGoogleTest/builds/105824144)

Could anyone help me, I cannot find out why I have 2 jobs for suite1.

---

<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:** [March 26, 2019, 3:16pm UTC](https://travis-ci.community/t/included-env-in-job-repeated-when-is-run-in-docker/2793/2 "2019-03-26T15:16:24Z")

</div>

You have two jobs defined with `env`:

> <https://github.com/murcraft/ProtractorGoogleTest/blob/7192042b47a050272bd6adcbeea56fac78ff5bdf/.travis.yml#L17-L19>

  
These belong to the default `Test` stage, as described in [https://docs.travis-ci.com/user/build-stages/#naming-your-build-stages](https://docs.travis-ci.com/user/build-stages/#naming-your-build-stages).

You have 2 additional jobs in

> <https://github.com/murcraft/ProtractorGoogleTest/blob/7192042b47a050272bd6adcbeea56fac78ff5bdf/.travis.yml#L21-L38>

  
one in `Build docker image`, and the other in `Test`.

---

<div class="post-metadata">

**Author:** ![murcraft](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/murcraft/32/2664_2.png) [@murcraft](https://travis-ci.community/u/murcraft)\
**Post date:** [March 27, 2019, 12:14pm UTC](https://travis-ci.community/t/included-env-in-job-repeated-when-is-run-in-docker/2793/3 "2019-03-27T12:14:40Z")

</div>

Ok, thanks. How can I have only 2 jobs in stage test? Used env “suite” should define new job, i.e.  
test  
1t job - env = suite1  
2d job - env = suite2  
But I use the same script for yhese two suites. I cannot find where I have to set env for stage test.

---

<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:** [March 27, 2019, 1:56pm UTC](https://travis-ci.community/t/included-env-in-job-repeated-when-is-run-in-docker/2793/4 "2019-03-27T13:56:38Z")

</div>

Drop the “test” job in `jobs.include`. If the `script` is meant to be shared by the two jobs in the “test” stage (one with `suite1`, and the other with `suite2`), then defining `script` at the top level will result in the configuration you want.

```auto
env:
  - suite=suite1
  - suite=suite2
script: # this will be shared by the two jobs above
  - mkdir allure-results
  ⋮
jobs:
  include:
  - stage: build docker image
    env: suite=null
    script: # this will override the `script` defined at the top level
    - echo …
  ⋮

```

---

<div class="post-metadata">

**Author:** ![murcraft](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/murcraft/32/2664_2.png) [@murcraft](https://travis-ci.community/u/murcraft)\
**Post date:** [March 27, 2019, 2:33pm UTC](https://travis-ci.community/t/included-env-in-job-repeated-when-is-run-in-docker/2793/5 "2019-03-27T14:33:40Z")

</div>

Thanks, it works. But if I want to run the stage: build docker image firstly and after finishing this job - to run suite1 and suite2. Because my suite1 and suite2 are depended from Docker image.

---

<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:** [March 27, 2019, 6:24pm UTC](https://travis-ci.community/t/included-env-in-job-repeated-when-is-run-in-docker/2793/6 "2019-03-27T18:24:45Z")

</div>

Please read the document. [https://docs.travis-ci.com/user/build-stages/#specifying-stage-order-and-conditions](https://docs.travis-ci.com/user/build-stages/#specifying-stage-order-and-conditions)

---

<div class="post-metadata">

**Author:** ![murcraft](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/murcraft/32/2664_2.png) [@murcraft](https://travis-ci.community/u/murcraft)\
**Post date:** [March 28, 2019, 7:01am UTC](https://travis-ci.community/t/included-env-in-job-repeated-when-is-run-in-docker/2793/7 "2019-03-28T07:01:16Z")

</div>

It helps, thanks!  
I deleted test from jobs and included  
services:  
 - docker  
So, this configuration works in right way:

> `dist: trusty`  
> `services:`  
> ` - docker`
> 
> `stages:`  
> `- docker-build`  
> `- test`
> 
> `env:`  
> ` - suite=suite1`  
> ` - suite=suite2`
> 
> `script:`  
> `- mkdir allure-results`  
> `...`
> 
> `jobs:`  
> ` include:`  
> ` - stage: docker-build`  
> ` env: suite=null`  
> ` script:`  
> ` - echo ...`
