Travis Workspaces

Workspaces

Workspaces allow jobs within a build to share files. They are useful when you want to use build artifacts from a previous job; for example, you create a cache that can be used in multiple jobs later.

Usage

The best build practices when using Workspaces is, it is best to create a workspace in one stage and then use it in subsequent stages. So, for example, in your .travis.yml file this is how workspaces would work:

jobs:
  include:
    - stage: warm_cache
      script:
        - echo "foo" > foo.txt
      workspaces:
        create:
          name: ws1
          paths:
            - foo.txt
    - stage: use_cache
      workspaces:
        use: ws1
      script:
        - cat foo.txt || true

As you can see each workspace has a unique name within a build. It is specified by the name key when it is created with workspaces.create, and by the value when it is used with workspaces.use.

In the above example, the workspace named ws1 is created by the only job in the warm_cache stage. The workspace is subsequently consumed in the use_cache stage.

Conclusion

As always, if you have any questions about this tutorial, please email me at montana@travis-ci.org and I will assist you.

Happy building!