Build Stages: Share files via S3

This example has 2 build stages:

  • Two jobs that set up files on S3.
  • One job that uses both files from stage 1.

Here’s what the .travis.yml config could look like:

env:
  global:
    # include $HOME/.local/bin for `aws`
    - PATH=$HOME/.local/bin:$PATH

before_install:
  # set up awscli packages
  - pip install --user awscli
  - mkdir -p ~/$TRAVIS_BUILD_NUMBER
  - aws s3 sync s3://travis-build-stages-shared-storage-test/$TRAVIS_BUILD_NUMBER ~/$TRAVIS_BUILD_NUMBER

jobs:
  include:
    - stage: setup files
      script: echo one | tee > ~/$TRAVIS_BUILD_NUMBER/one
    - stage: setup files
      script: echo two | tee > ~/$TRAVIS_BUILD_NUMBER/two
    - stage: use shared files
      script:
        - cat ~/$TRAVIS_BUILD_NUMBER/*
      after_success:
        - aws s3 rm --recursive s3://travis-build-stages-shared-storage-test/$TRAVIS_BUILD_NUMBER # clean up after ourselves

after_success:
  - aws s3 sync ~/$TRAVIS_BUILD_NUMBER s3://travis-build-stages-shared-storage-test/$TRAVIS_BUILD_NUMBER

This is how the build matrix would look like:

image

You can find the code for this example on our demo repository: