LoginSignup
8
6

More than 5 years have passed since last update.

CircleCI 2.0の新しいDocker imageを利用して、Androidのビルドとdangerの実行を行う

Last updated at Posted at 2017-09-12

CircleCI 2.0でAndroid関連の静的解析結果をPullRequestで指摘する - Qiita で、CircleCI側が用意したdockerイメージにRubyの実行環境が入っていなかったため、回りくどいことをしていました。
(workflowsを利用して、コードをattachしつつ、別のdockerイメージを動かす)

その記事をベトナムの子会社に共有して数時間後、 https://github.com/circleci/circleci-images/pull/75/files というPRを教えてもらいました。
CircleCIの提供しているdockerイメージに、Rubyの実行環境が入ったようです。
これを使うことで、Rubyのコンテナは必要なくなりそうです。

ということで、やってみました。

変更点例

一部消しすぎてたので、追加修正。
https://github.com/noboru-i/SlideViewer/pull/80/files

変更後の .circleci/config.yml

固有の部分や、重要じゃない部分などを省くと、下記のようなイメージになります。

version: 2

defaults: &defaults
  working_directory: ~/code
  docker:
    - image: circleci/android:api-26-alpha
  environment:
    JVM_OPTS: -Xmx3200m

jobs:
  build:
    <<: *defaults
    steps:
      - checkout
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - run:
          name: Download Dependencies
          command: ./gradlew androidDependencies
      - save_cache:
          paths:
            - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}

      - restore_cache:
          key: gems-{{ checksum "Gemfile.lock" }}
      - run: bundle install --path vendor/bundle
      - save_cache:
          paths:
            - vendor/bundle
          key: gems-{{ checksum "Gemfile.lock" }}

      - run:
          name: Check lint
          command: ./gradlew :app:check -x test
      - run:
          name: Run danger
          command: bundle exec danger

      - run:
          name: Build apk
          command: ./gradlew :app:assembleDebug
      - store_artifacts:
          path: app/build/outputs/apk/app-debug.apk
          destination: app-debug.apk
      - persist_to_workspace:
          root: ~/code
          paths:
            - .

  deploy:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/code
      - run:
          name: Build apk
          command: ./gradlew :app:assembleRelease
      - store_artifacts:
          path: app/build/outputs/apk/app-release.apk
          destination: app-release.apk
workflows:
  version: 2
  build_and_deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: master

これで、前回と同じようなdangerの実行を、CircleCI 2.0のスピードで実行できるようになりました。

8
6
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
8
6