构建阶段:部署到 Heroku

此示例有 5 个构建阶段

  • 两个作业在阶段 1 上并行运行单元测试。
  • 一个作业将应用程序部署到 Heroku 暂存环境。
  • 一个作业在 Heroku 上测试暂存部署。
  • 一个作业将应用程序部署到 Heroku 生产环境。
  • 一个作业在 Heroku 上测试生产部署。

以下是 .travis.yml 配置可能的样子

jobs:
  include:
    - stage: unit tests
      script: "Running unit tests (1)"
    - stage: unit tests
      script: "Running unit tests (2)"
    - stage: deploy to staging
      script: skip
      deploy: &heroku
        provider: heroku
        app: sf-stages-staging
        api_key: $HEROKU_AUTH_TOKEN
    - stage: test staging
      script: 'curl http://sf-stages-staging.herokuapp.com'
    - stage: deploy to production
      script: skip
      deploy:
        <<: *heroku
        app: sf-stages-production
    - stage: test production
      script: 'curl http://sf-stages-production.herokuapp.com'

构建矩阵将如下所示

image

您可以在我们的 演示存储库 中找到此示例的代码