# How to use stages in multi language builds

**URL:** <https://travis-ci.community/t/how-to-use-stages-in-multi-language-builds/2084>\
**Category:** Travis CI Discussions & Feedback\
**Created:** [February 1, 2019, 11:25am UTC](https://travis-ci.community/t/how-to-use-stages-in-multi-language-builds/2084 "2019-02-01T11:25:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![knurek](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@knurek](https://travis-ci.community/u/knurek)\
**Post date:** [February 1, 2019, 11:25am UTC](https://travis-ci.community/t/how-to-use-stages-in-multi-language-builds/2084/1 "2019-02-01T11:25:04Z")

</div>

I can’t quite wrap my head around the documentation and the examples to figure out what I need.  
I have a repo that contains golang and node\_js code. I want to run two stages that

1. tests/builds the go code
2. tests/builds the js code  
and then the output of both those builds should run in an `after_success` step to build a single docker image with the compiled files.

* * *

I’ve tried with the `matrix` but am getting two docker images built:

```auto
services:
  - docker

matrix:
  include:
    - language: go
      go:
        - "1.11"
      script:
        - make test
        - make build

    - language: node_js
      node_js:
        - "7"
      script: yarn run build

after_success:
  - docker build

```

---

<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 1, 2019, 1:24pm UTC](https://travis-ci.community/t/how-to-use-stages-in-multi-language-builds/2084/2 "2019-02-01T13:24:28Z")

</div>

What does this configuration give you, and how does it fall short of your expectations?

---

<div class="post-metadata">

**Author:** ![knurek](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@knurek](https://travis-ci.community/u/knurek)\
**Post date:** [February 4, 2019, 11:21am UTC](https://travis-ci.community/t/how-to-use-stages-in-multi-language-builds/2084/3 "2019-02-04T11:21:56Z")

</div>

The problem is that the `js` build takes a little bit longer to execute, but the `after_success` executes before `yarn run build` is complete, and the files generated are not in the docker image.

My expectation is that `after_success` only runs once, after all jobs are complete and successful.

---

<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 4, 2019, 12:51pm UTC](https://travis-ci.community/t/how-to-use-stages-in-multi-language-builds/2084/4 "2019-02-04T12:51:52Z")

</div>

If you want these two jobs to be in different stages (and guarantee sequential execution), you need to define different `stage` values. This is explained in [https://docs.travis-ci.com/user/build-stages/](https://docs.travis-ci.com/user/build-stages/).

---

<div class="post-metadata">

**Author:** ![knurek](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@knurek](https://travis-ci.community/u/knurek)\
**Post date:** [February 4, 2019, 1:43pm UTC](https://travis-ci.community/t/how-to-use-stages-in-multi-language-builds/2084/5 "2019-02-04T13:43:09Z")

</div>

The ordering of the jobs doesn’t matter, they just have to all run before `after_success`

But, since running them sequentially isn’t a hard requirement at this point, using stages would be ok with me. However the documentation of stages (or any examples I found) does not show me how to use multiple languages. Can you take my example and convert it to use 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 4, 2019, 2:59pm UTC](https://travis-ci.community/t/how-to-use-stages-in-multi-language-builds/2084/6 "2019-02-04T14:59:16Z")

</div>

I think I was overlooking a critical element of your question.

Jobs are run independently within a build. One job does not have any clue as to what the rest are doing. So,

> [@knurek](#):
>
> then the output of both those builds should run in an `after_success` step to build a single docker image with the compiled files.

This is not possible.

I suggest combining the builds into a single job. Use `nvm` to manage Node.js versions if necessary.

---

<div class="post-metadata">

**Author:** ![knurek](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@knurek](https://travis-ci.community/u/knurek)\
**Post date:** [February 4, 2019, 3:18pm UTC](https://travis-ci.community/t/how-to-use-stages-in-multi-language-builds/2084/7 "2019-02-04T15:18:04Z")

</div>

> [@BanzaiMan](#):
>
> I suggest combining the builds into a single job.

ok, that was something I looked into for a workaround already.  
What I wanted to do was use a go image as a base, then install node on it, and then use that to build the jobs, but using a custom image seemed like a lot more overhead to do this.

so…can you give me an example of running these two languages in one job?
