Travis CI
01 / 02

Build Lifecycle, Config Basics & Matrix Builds

Build Lifecycle, Config Basics & Matrix Builds

A Basic .travis.yml

language: node_js
node_js:
  - "18"
  - "20"
  - "22"

cache:
  directories:
    - node_modules

before_install:
  - sudo apt-get update

install:
  - npm ci

script:
  - npm test
  - npm run lint

branches:
  only:
    - main

The build matrix here (3 Node versions) runs the same config across each combination — no manual duplication. cache persists node_modules between runs, avoiding a full reinstall each time. branches limits which branches even trigger a build.

Lifecycle Order

before_install (system-level prep) → install (project dependencies) → before_script → script (the actual test run, whose exit code decides pass/fail) → after_success or after_failure → after_script. Keeping install (setup) separate from script (verification) means a build's failure LOCATION signals what kind of problem occurred — setup issue vs. actual test failure.

allow_failure & Ephemeral Environments

matrix:
  allow_failures:
    - node_js: "nightly"
  include:
    - node_js: "nightly"

allow_failure gets visibility into an experimental version's compatibility without blocking overall build success. Every build runs in a fresh, isolated environment — no leftover state from a previous build, keeping results reproducible.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free