LoginSignup
0
0

More than 3 years have passed since last update.

TravisCIでジョブ間データ受け渡し

Last updated at Posted at 2020-07-16

FlutterアプリのCIとしてTravisCIを使いはじめました。
その際に、ビルド番号をAndroid/iOSのビルドで共通化したかったので調べたことをメモ。

やりたいこと

以下のステージがあったとして、prepareステージで作成したファイルを後続のステージで読み込みたい。

stages:
  - prepare
  - build

調査

公式は以下にあるようにS3とかSCP使って永続化してねって言っています。
https://docs.travis-ci.com/user/build-stages/#data-persistence-between-stages-and-jobs

S3にTRAVIS_BUILD_NUMBERを使って取得できるようにしたら行けるのかなっと思いましたが、ちょっとS3は使えないので却下。
SCPもアクセスできる端末ないので却下でした。

workspaces(Beta #2020/7/16)

探していると、Workspacesって機能があるよと。(https://stackoverflow.com/questions/53931069/pass-information-between-stages-in-travis-ci)

Using Workspaces

使い方はかんたん。
保存する側のJobと使用する側のJobにworkspaces要素を追加するだけ。

jobs:
  include:
    - stage: prepare
      os: linux
      workspaces:
        create:
          name: hoge # <- 任意のキー、使用する際に使う
          paths: hogehoge.txt
      script:
        - echo "prepare" > hogehoge.txt
    - stage: test
      os: linux
      workspaces:
        use: hoge
      script:
        - cat hogehoge.txt
    - stage: build
      os: linux
      workspaces:
        use: hoge
      script:
        - cat hogehoge.txt

注意

Linux同士のJobはこれで大丈夫だが、Linux->Macだとディレクトリ構成が異なるので使用できない
TravisコミュニティでもIssuesが上がっている。
https://travis-ci.community/t/workspaces-do-not-work-nicely-with-cross-platform-builds/4461

以下のPRで対応中のようです。
https://github.com/travis-ci/travis-build/pull/1923

原因

Linux側のHOME(/home/travis/)とMac側のHOME(/Users/travis/)が異なるので、復元時にMacにLinuxのHOMEが作れなくて失敗する。
workspaces.create.pathsを絶対パスに正規化してしまう様子。

回避策(2020/7/16時点)

とりあえずマージされるまではこの方法でいけたのでメモ(Linux->Macのみ)
Linux/Macで共通に使用できる/tmpディレクトリを使う。


jobs:
  include:
    - stage: prepare
      os: linux
      workspaces:
        create:
          name: hoge # <- 任意のキー、使用する際に使う
          paths: /tmp/hogehoge.txt
      script:
        - echo "prepare" > hogehoge.txt
        - cp hogehoge.txt /tmp/hogehoge.txt
    - stage: build
      os: linux
      workspaces:
        use: hoge
      script:
        - cat /tmp/hogehoge.txt
    - stage: build
      os: osx
      workspaces:
        use: hoge
      script:
        - cat /tmp/hogehoge.txt

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0