# Multiline \`script:\` is running without errexit?

**URL:** https://travis-ci.community/t/multiline-script-is-running-without-errexit/7644
**Category:** Travis CI Discussions & Feedback
**Tags:** travis-build, travis-yml
**Created:** [March 19, 2020, 6:03am UTC](https://travis-ci.community/t/multiline-script-is-running-without-errexit/7644 "2020-03-19T06:03:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![noloader](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/noloader/32/2971_2.png) [@noloader](https://travis-ci.community/u/noloader)
#### Post date: [March 19, 2020, 6:03am UTC](https://travis-ci.community/t/multiline-script-is-running-without-errexit/7644/1 "2020-03-19T06:03:46Z")

</div>

Hi Everyone,

We have a multiline script like:

```auto
script:
  - |
    if [["$TRAVIS_OS_NAME" == "linux"]]; then
      ./configure
      make -j2
      make test
      ./custom-a.sh
    else
      ./configure
      make -j2
      make test
      ./custom-b.sh
    fi

```

The problem we are experiencing is, when `configure`, `make` and `custom-x.sh` fails the script continues to execute. For example, [Job 154029345](https://travis-ci.com/github/noloader/nsd/builds/154029345) fails during `make`, but then continues onto the `make test` (which fails), and then tries to run the self tests (which fails).

I’ve been trying to find the controlling document that explains multiline scripting, but I can’t find it at [docs.travis-ci.com](http://docs.travis-ci.com). (A link to the docs would be helpful).

How do we make the multiline script fail when the first command fails?

* * *

We know we can wrap everything in a top-level script that calls `make`, …, `custom-b.sh`. The problem is, we lose the output of custom scripts when they drop below the top level. So we want to keep everything at the top level so we can see the output.

For example, if we change this to:

```auto
    if [["$TRAVIS_OS_NAME" == "linux"]]; then
      ./do-linux.sh
    else
      ...
    fi

```

with `do-linux.sh`:

```auto
#!/usr/bin/env bash

./configure
make -j2
make test
./custom-a.sh

```

then we lose `configure` and `custom-a.sh` output.

---

<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: [March 19, 2020, 9:20am UTC](https://travis-ci.community/t/multiline-script-is-running-without-errexit/7644/2 "2020-03-19T09:20:17Z")

</div>

This is by design.  
User commands run without `errexit` – because, by necessity, [they are run with `eval` in the same shell as other build logic](https://github.com/travis-ci/travis-build/blob/bc5ddbd594d61c1135d931af6dfa7da7c45b4b13/lib/travis/build/bash/travis_cmd.bash#L57) (so that environment changes they make are seen by further commands), so `errexit` would break the enveloping internal logic.

You have a few options here:

- Put the commands into a separate script and run it (with `-e` or whatever), as a subprocess.

- Invoke consecutive commands as

- Run the block in a subshell with `-e`:

---

<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: [March 19, 2020, 9:23am UTC](https://travis-ci.community/t/multiline-script-is-running-without-errexit/7644/3 "2020-03-19T09:23:45Z")

</div>

> [@noloader](#):
>
> The problem is, we lose the output of custom scripts when they drop below the top level.

I don’t understand what you mean here. This sounds not normal, but most probably, it’s a fault in the build logic or a confusion about how things are being logged. Please give an example if you wish to pursue this further.
