Ardrey 情報マガジン

travisyml

📅 October 30, 2026📖 Verified Publication
```html Travis CI .travis.yml — Complete Guide (2024–2026)

.travis.yml — The Definitive Guide to Configuring Travis CI (2024–2026)

Key Takeaways

  • .travis.yml is the single configuration file that tells Travis CI how to build, test, and deploy your project.
  • It supports all major languages: Node.js, Python, Ruby, Go, Java, PHP, C/C++, and generic Docker workflows.
  • Matrix builds let you test against multiple language versions, OSs, and environments simultaneously — reducing manual configuration.
  • Common failure reasons include YAML syntax errors, missing environment variables, and misconfigured deploy sections.
  • Travis CI shifted to a usage-based billing model in 2021; free accounts now have limited monthly build minutes on public repositories.
  • Alternatives like GitHub Actions, CircleCI, and GitLab CI offer comparable or superior features — know when to migrate.
  • A minimal valid .travis.yml requires only a language field, but production configs need before_install, install, script, and optionally deploy sections.

What Is .travis.yml?

.travis.yml is the YAML configuration file used by Travis CI, one of the most established continuous integration and continuous deployment (CI/CD) platforms. Placed in the root of your repository, it defines everything Travis CI needs to clone your code, set up dependencies, run tests, and deploy artifacts.

Despite growing competition from GitHub Actions and GitLab CI, millions of open-source and commercial projects still rely on .travis.yml. Understanding it thoroughly saves hours of debugging flaky builds and accelerates your CI/CD pipeline setup.

How to Write a Valid .travis.yml — Step-by-Step

A well-structured .travis.yml follows a predictable pattern. Below is a template you can adapt for any language ecosystem.

Minimal Configuration

language: node_js
node_js:
  - "18"
  - "20"
  - "22"
branches:
  only:
    - main
    - master

Production-Grade Configuration

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

cache:
  npm: true

env:
  global:
    - COVERAGE_TOKEN: secure <encrypted-value>
    - NODE_ENV: test

matrix:
  include:
    - node_js: "18"
      before_script: npm run lint
    - node_js: "20"
      env: SECURITY_SCAN=true
    - node_js: "22"
      sudo: required
      services: docker

before_install:
  - node --version
  - npm --version

install:
  - npm ci

before_script:
  - npm run build

script:
  - npm test
  - npm run coverage

after_success:
  - bash <coverage-report-script>

deploy:
  provider: npm
  email: <your-email>
  api_key:
    secure: <encrypted-npm-token>
  skip_cleanup: true
  on:
    tags: true
    branch: main

notifications:
  email:
    on_success: change
    on_failure: always

.travis.yml vs. GitHub Actions vs. GitLab CI — Quick Comparison

Feature Travis CI (.travis.yml) GitHub Actions (workflow YAML) GitLab CI (.gitlab-ci.yml)
Configuration Syntax YAML (.travis.yml) YAML (.github/workflows/*.yml) YAML (.gitlab-ci.yml)
Free Tier (Public Repos) Limited build minutes 2,000 min/month (500 min/shared runners) Unlimited (with shared runner minutes)
Free Tier (Private Repos) 1,000 min/month (paid plans scale up) 500 min/month (shared runners) Unlimited with self-hosted or shared runners
Matrix Builds Native (language, os, env matrices) Native (strategy.matrix) Native (parallel + variables)
Container Support Native (services + custom Docker) Native (Docker containers) Native (Docker + Kubernetes)
Deploy Providers Built-in (npm, Heroku, AWS, Docker, etc.) Actions marketplace + custom Built-in + custom scripts
Ecosystem Maturity High (10+ years) Very High (rapidly evolving) High (mature, full DevOps platform)
Learning Curve Moderate Moderate (more verbose) Moderate (steeper for pipelines)
Best For Existing Travis users, simple projects GitHub-hosted repos, modern workflows GitLab-hosted repos, full CI/CD

Production .travis.yml Deployment Checklist

Before committing your configuration, verify every item below to prevent build failures and security leaks.

  • YAML validity: Run through a linter (yamllint) or Travis CI's config validator.
  • Sensitive data secured: All tokens, API keys, and secrets use secure: encryption — never hardcode plaintext.
  • Language version pinned: Specify exact major/minor versions (e.g., "20.11") instead of aliases for reproducibility.
  • Cache configured: Enable cache: npm (or pip, bundler, go, etc.) to speed up subsequent builds.
  • Services declared: Add any required background services (PostgreSQL, Redis, MySQL) under