Help us understand the problem. What is going on with this article?

Travis CIのビルド結果を回収する

More than 5 years have passed since last update.

after scriptでどこかにアップロードすればいい。
やってみる。

ゴール

例としてカバレッジ結果をS3アップロードする。

準備

SimpleCov

SimpleCovを使ってカバレッジ結果を出力できるようにする。
https://github.com/arukoh/sandbox/commit/09ff8655bf3ba7f94ab1d76ee108187a45a4c507

S3バケット作成

  1. 結果をアップロードするS3バケットを作成する。(略)
  2. 'travis'ユーザを作成しポリシーを定義する
{
  "Statement": [
    {
      "Action": [
        "s3:ListBucket", 
        "s3:ListObject",
        "s3:PutObject",
        "s3:PutObjectAcl"
      ],
      "Resource": [
        "arn:aws:s3:::arukoh-travis-builds",
        "arn:aws:s3:::arukoh-travis-builds/*"
      ],
      "Effect": "Allow"
    }
  ]
}

.travis.yml編集

  1. 環境変数でCredentialsを渡す
  2. s3cmdをインストールする
  3. s3cmd syncで指定ディレクトリをアップロード(sync)する

環境変数でCredentialsを渡す

Travis CIでsecret valueを扱う

$ travis encrypt TRAVIS_AWS_ACCESS_KEY_ID=XXXX
$ travis encrypt TRAVIS_AWS_SECRET_ACCESS_KEY=YYYY

s3cmdをインストールする

sudo apt-get install -y s3cmd

s3cmd syncで指定ディレクトリをアップロード(sync)する

$ s3cmd sync -r -P --delete-removed --config=.s3cfg ${TARGET} s3://${BUCKET_NAME}/${PATH}

各オプションはManページで。

まとめ

https://github.com/arukoh/sandbox/commit/ffedd0706d88c5e4f920680caf79a1c999047f3e

.travis.yml
env:
  global:
    - secure: "ENCRYPTED_AWS_ACCESS_KEY_ID"
    - secure: "ENCRYPTED_AWS_SECRET_ACCESS_KEY"

before_script:
  - sudo apt-get install -y s3cmd

after_script:
  - echo "access_key = $TRAVIS_AWS_ACCESS_KEY_ID" >> .s3cfg
  - echo "secret_key = $TRAVIS_AWS_SECRET_ACCESS_KEY" >> .s3cfg
  - s3cmd sync -r -P --delete-removed --config=.s3cfg coverage/ s3://arukoh-travis-builds/sandbox/coverage/

結果

https://s3-ap-northeast-1.amazonaws.com/arukoh-travis-builds/sandbox/coverage/index.html#_AllFiles

travis-ciログ
...
$ export TRAVIS_AWS_ACCESS_KEY_ID=[secure]
$ export TRAVIS_AWS_SECRET_ACCESS_KEY=[secure]
...
$ sudo apt-get install -y s3cmd
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  python-support
The following NEW packages will be installed:
  python-support s3cmd
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 84.9 kB of archives.
After this operation, 462 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/universe python-support all 1.0.14ubuntu2 [26.1 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise/universe s3cmd all 1.0.0-1 [58.8 kB]
Fetched 84.9 kB in 0s (403 kB/s)
Selecting previously unselected package python-support.
(Reading database ... 61200 files and directories currently installed.)
Unpacking python-support (from .../python-support_1.0.14ubuntu2_all.deb) ...
Selecting previously unselected package s3cmd.
Unpacking s3cmd (from .../archives/s3cmd_1.0.0-1_all.deb) ...
Processing triggers for man-db ...
Setting up python-support (1.0.14ubuntu2) ...
Setting up s3cmd (1.0.0-1) ...
Processing triggers for python-support ...
...
$ echo "access_key = $TRAVIS_AWS_ACCESS_KEY_ID" >> .s3cfg
$ echo "secret_key = $TRAVIS_AWS_SECRET_ACCESS_KEY" >> .s3cfg
$ s3cmd sync -r -P --delete-removed --config=.s3cfg coverage/ s3://arukoh-travis-builds/sandbox/coverage/
coverage/.last_run.json -> s3://arukoh-travis-builds/sandbox/coverage/.last_run.json  [1 of 43]
 51 of 51   100% in    1s    42.96 B/s  done
coverage/.resultset.json -> s3://arukoh-travis-builds/sandbox/coverage/.resultset.json  [2 of 43]
 277 of 277   100% in    0s   385.01 B/s  done
coverage/assets/0.7.1/application.css -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/application.css  [3 of 43]
 39731 of 39731   100% in    1s    31.93 kB/s  done
coverage/assets/0.7.1/application.js -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/application.js  [4 of 43]
 194216 of 194216   100% in    2s    74.06 kB/s  done
coverage/assets/0.7.1/fancybox/blank.gif -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/blank.gif  [5 of 43]
 43 of 43   100% in    0s    58.58 B/s  done
coverage/assets/0.7.1/fancybox/fancy_close.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_close.png  [6 of 43]
 1517 of 1517   100% in    0s     2.14 kB/s  done
coverage/assets/0.7.1/fancybox/fancy_loading.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_loading.png  [7 of 43]
 10195 of 10195   100% in    0s    11.71 kB/s  done
coverage/assets/0.7.1/fancybox/fancy_nav_left.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_nav_left.png  [8 of 43]
 1446 of 1446   100% in    0s  1994.78 B/s  done
coverage/assets/0.7.1/fancybox/fancy_nav_right.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_nav_right.png  [9 of 43]
 1454 of 1454   100% in    0s     2.02 kB/s  done
coverage/assets/0.7.1/fancybox/fancy_shadow_e.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_shadow_e.png  [10 of 43]
 107 of 107   100% in    0s   144.02 B/s  done
coverage/assets/0.7.1/fancybox/fancy_shadow_n.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_shadow_n.png  [11 of 43]
 106 of 106   100% in    0s   147.18 B/s  done
coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png  [12 of 43]
 347 of 347   100% in    0s   478.28 B/s  done
coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png  [13 of 43]
 324 of 324   100% in    0s   428.77 B/s  done
coverage/assets/0.7.1/fancybox/fancy_shadow_s.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_shadow_s.png  [14 of 43]
 111 of 111   100% in    0s   153.12 B/s  done
coverage/assets/0.7.1/fancybox/fancy_shadow_se.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_shadow_se.png  [15 of 43]
 352 of 352   100% in    0s   478.54 B/s  done
coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png  [16 of 43]
 340 of 340   100% in    0s   449.98 B/s  done
coverage/assets/0.7.1/fancybox/fancy_shadow_w.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_shadow_w.png  [17 of 43]
 103 of 103   100% in    0s   145.03 B/s  done
coverage/assets/0.7.1/fancybox/fancy_title_left.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_title_left.png  [18 of 43]
 503 of 503   100% in    0s   694.12 B/s  done
coverage/assets/0.7.1/fancybox/fancy_title_main.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_title_main.png  [19 of 43]
 96 of 96   100% in    0s   135.41 B/s  done
coverage/assets/0.7.1/fancybox/fancy_title_over.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_title_over.png  [20 of 43]
 70 of 70   100% in    0s    97.39 B/s  done
coverage/assets/0.7.1/fancybox/fancy_title_right.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancy_title_right.png  [21 of 43]
 506 of 506   100% in    0s   743.33 B/s  done
coverage/assets/0.7.1/fancybox/fancybox-x.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancybox-x.png  [22 of 43]
 203 of 203   100% in    0s   298.09 B/s  done
coverage/assets/0.7.1/fancybox/fancybox-y.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancybox-y.png  [23 of 43]
 176 of 176   100% in    0s   239.43 B/s  done
coverage/assets/0.7.1/fancybox/fancybox.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/fancybox/fancybox.png  [24 of 43]
 15287 of 15287   100% in    0s    17.78 kB/s  done
coverage/assets/0.7.1/favicon_green.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/favicon_green.png  [25 of 43]
 1009 of 1009   100% in    0s  1329.52 B/s  done
coverage/assets/0.7.1/favicon_red.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/favicon_red.png  [26 of 43]
 1009 of 1009   100% in    0s  1370.22 B/s  done
coverage/assets/0.7.1/favicon_yellow.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/favicon_yellow.png  [27 of 43]
 1009 of 1009   100% in    0s  1401.57 B/s  done
coverage/assets/0.7.1/loading.gif -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/loading.gif  [28 of 43]
 7247 of 7247   100% in    0s     8.58 kB/s  done
coverage/assets/0.7.1/magnify.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/magnify.png  [29 of 43]
 1301 of 1301   100% in    0s  1747.54 B/s  done
coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png  [30 of 43]
 180 of 180   100% in    0s   259.63 B/s  done
coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png  [31 of 43]
 178 of 178   100% in    0s   235.57 B/s  done
coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png  [32 of 43]
 120 of 120   100% in    0s   167.94 B/s  done
coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png  [33 of 43]
 105 of 105   100% in    0s   143.03 B/s  done
coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png  [34 of 43]
 111 of 111   100% in    0s   153.73 B/s  done
coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png  [35 of 43]
 110 of 110   100% in    0s   160.43 B/s  done
coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png  [36 of 43]
 119 of 119   100% in    0s   164.23 B/s  done
coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png  [37 of 43]
 101 of 101   100% in    0s   138.56 B/s  done
coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png  [38 of 43]
 4369 of 4369   100% in    0s     4.65 kB/s  done
coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png  [39 of 43]
 4369 of 4369   100% in    0s     4.83 kB/s  done
coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png  [40 of 43]
 4369 of 4369   100% in    0s     4.84 kB/s  done
coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png  [41 of 43]
 4369 of 4369   100% in    0s     4.64 kB/s  done
coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png -> s3://arukoh-travis-builds/sandbox/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png  [42 of 43]
 4369 of 4369   100% in    0s     4.85 kB/s  done
coverage/index.html -> s3://arukoh-travis-builds/sandbox/coverage/index.html  [43 of 43]
 4608 of 4608   100% in    0s     5.32 kB/s  done
Done. Uploaded 306613 bytes in 35.3 seconds, 8.49 kB/s
jrits
信頼と魅力のある先進のITをもとに、お客様のワークスタイル・イノベーションの実現を目指します。
http://www.jrits.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away