LoginSignup
1
0

More than 1 year has passed since last update.

Azure PipelinesのYAMLでAndroidアプリのApp Center配布パイプラインを構築する方法

Last updated at Posted at 2021-03-08

「Azure PipelinesのYAMLでAndroidアプリのCI/CD環境を構築する」は3部構成です。
記事を順番に読み進めると、Azure PipelinesでAndroidアプリのCI/CD環境が構築できるようになります。

  • 第一部:CI環境の構築
  • 第二部:App Center配布パイプラインの構築 ←イマココ
  • 第三部:Google Play Console配布パイプラインの構築(未投稿)

はじめに

Azure Pipelinesを使い、AndroidアプリをApp Centerへ配布するCDを構築します。

本記事で説明しないこと

  • Azure Pipelinesの概要や基本的な操作方法
    私が以前書いた記事が参考になると思います
  • Visual Studio App Centerの概要や基本的な操作方法
  • CI環境の構築で説明した内容
    以前説明した内容を説明するのは冗長なのでしません

App Centerのコネクションを追加

Azure PipelinesのYAMLでiOSアプリのApp Center配布パイプラインを構築する方法 と同様なので省略します。

キーストアのアップロード

必要に応じてキーストアをSecure fileへアップロードします。
アップロードの方法は こちら をご参照ください。

私はApp Center用のキーストアはリポジトリに直接コミットしており、Secure fileは使っていません。

キーストアと鍵のパスワードの追加

必要に応じてキーストアと鍵のパスワードをVariablesに追加します。
追加方法は こちら をご参照ください。

私はApp Center用のキーストアと鍵のパスワードは /app/build.gradle に直接書いています。

設定ファイルの作成

今回はビルドタイプを debug に固定し、プロダクトフレーバーを以下の3つすべてでApp Centerに配布できるようにします。

  • develop
  • staging
  • production

プロダクトフレーバーが異なる以外は同じ処理なので、Azure DevOpsのテンプレートを利用し、共通処理を別のYAMLファイルに抜き出します。

まずは全プロダクトフレーバーの設定ファイルを作成します。
見てわかる通り productFlavor に渡す値のみ変えています。

distribute-appcenter-develop-debug.yml
name: $(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)

trigger: none

jobs:
- job: distribute_appcenter_develop_debug
  pool:
    vmImage: 'ubuntu-latest'

  steps:
  # App Centerへ配布
  - template: templates/distribute-appcenter-debug-template.yml
    parameters:
      productFlavor: 'develop'
distribute-appcenter-staging-debug.yml
name: $(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)

trigger: none

jobs:
- job: distribute_appcenter_staging_debug
  pool:
    vmImage: 'ubuntu-latest'

  steps:
  # App Centerへ配布
  - template: templates/distribute-appcenter-debug-template.yml
    parameters:
      productFlavor: 'staging'
distribute-appcenter-production-debug.yml
name: $(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)

trigger: none

jobs:
- job: distribute_appcenter_production_debug
  pool:
    vmImage: 'ubuntu-latest'

  steps:
  # App Centerへ配布
  - template: templates/distribute-appcenter-debug-template.yml
    parameters:
      productFlavor: 'production'

次にテンプレートを作成します。

templates/distribute-appcenter-debug-template.yml
parameters:
- name: productFlavor
  type: string

steps:
# JDKのセットアップ
- task: JavaToolInstaller@0
  inputs:
    versionSpec: '11'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: 'PreInstalled'

# 依存関係の出力
- script: ./gradlew androidDependencies
  displayName: Displays the Android dependencies of the project

# APKの生成
- script: ./gradlew assembleDebug
  displayName: Generate APK for debug

# アーティファクトのステージングへコピー
- task: CopyFiles@2
  inputs:
    Contents: |
      **/app/build/outputs/apk/${{ parameters.productFlavor }}/debug/app-${{ parameters.productFlavor }}-debug.apk
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

# アーティファクトへアップロード
- task: PublishBuildArtifacts@1
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: 'drop'
    publishLocation: 'Container'

# App Centerへ配布
- task: AppCenterDistribute@3
  inputs:
    serverEndpoint: 'App Center'
    appSlug: '{Organization}/{App}'
    appFile: '**/app/build/outputs/apk/${{ parameters.productFlavor }}/debug/app-${{ parameters.productFlavor }}-debug.apk'
    releaseNotesOption: 'input'
    releaseNotesInput: |
      - Product Flavor: ${{ parameters.productFlavor }}
      - Build Type: debug
      - Keystore: {Keystore name}
      - Build ID: $(Build.BuildId)
      - Build Number: $(Build.BuildNumber)
      - Reason: $(Build.Reason)
      - Requested For: $(Build.RequestedFor)
      - Source Branch: $(Build.SourceBranch)
      - Last Commit ID: $(Build.SourceVersion)
      - Last Commit Comment: $(Build.SourceVersionMessage)
      - Release Note: $(ReleaseNote)
    destinationType: 'groups'

App CenterはAAB形式に対応していないため、APK形式でアップロードします。
参考: https://github.com/microsoft/appcenter/issues/955

AAB形式でアップロードしようとすると、以下のエラーが出力されます。

##[error]{"code":"not_supported","message":"Error: Distribution of .aab is not supported for groups/testers"}

他は基本的に Azure PipelinesのYAMLでiOSアプリのApp Center配布パイプラインを構築する方法 と同様なので省略します。

おわりに

Azure PipelinesのYAMLでAndroidアプリをApp Centerへ配布することができました!

テンプレートを利用することで共通処理をまとめられ、設定ファイルがスッキリしました。

参考リンク

APK

Templates - Azure Pipelines

App Center

1
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
1
0