Xcode アプリのビルド、テスト、デプロイ

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

Azure Pipelines を使用して Xcode プロジェクトをビルドおよびデプロイする方法について説明します。

前提条件

パイプラインを作成する

  1. Azure DevOps 組織にサインインし、プロジェクトに移動します。

  2. [パイプライン] に移動し、最初のパイプラインを作成する場合は [新しいパイプライン] または [[パイプラインの作成] を選択します。

  3. 最初に、ソース コードの場所として GitHub を選択し、ウィザードの手順を実行します。

  4. サインインするために GitHub にリダイレクトされる場合があります。 その場合は、GitHub の資格情報を入力します。

  5. リポジトリの一覧が表示されたら、目的のリポジトリを選択します。

  6. Azure Pipelines アプリをインストールするために、GitHub にリダイレクトされる場合があります。 その場合は、[承認してインストール] を選択します。

[構成] タブが表示されたら、[Xcode] を選択します。

  1. 新しいパイプラインが表示されたら、YAML に目を通し、その動作を確認します。 準備ができたら、[保存および実行] を選択します。

    新しい YAML パイプラインの [保存および実行] ボタン

  2. 新しい azure-pipelines.yml ファイルを自分のリポジトリにコミットするように求められます。 メッセージを確認したら、[保存および実行] をもう一度選択します。

    パイプラインの動作を観察する場合は、ビルド ジョブを選択します。

    今作成して実行したパイプラインは、コードが Xcode テンプレートに適しているように見えるため、自動的に作成されました。

    これで、リポジトリで YAML パイプライン (azure-pipelines.yml) が稼働し、カスタマイズできるようになりました。

  3. パイプラインを変更する準備ができたら、[パイプライン] ページでそのパイプラインを選択し、azure-pipelines.yml ファイルを編集します。

パイプラインをカスタマイズするいくつかの一般的な方法については、以下のセクションを参照してください。

ヒント

このトピックの説明に従って YAML ファイルを変更するには、[パイプライン] ページでパイプラインを選択し、[編集] を選択して、azure-pipelines.yml ファイルのエディターを開きます。

ビルド環境

Azure Pipelines を使用すると、独自のインフラストラクチャを設定せずに Xcode でアプリを構築できます。 Xcode は、Azure Pipelines の Microsoft ホステッド macOS エージェントにプレインストールされています。 macOS エージェントを使用してビルドを実行できます。

プレインストールされている Xcode の正確なバージョンについては、Microsoft によってホストされるエージェントに関するページを参照してください。

リポジトリのルートに azure-pipelines.yml という名前のファイルを作成します。 次に、次のスニペットを azure-pipelines.yml ファイルに追加して、適切なエージェント プールを選択します。

# https://learn.microsoft.com/azure/devops/pipelines/ecosystems/xcode
pool:
  vmImage: 'macOS-latest'

Xcode を使用してアプリをビルドする

Xcode を使用してアプリをビルドするには、次のスニペットを azure-pipelines.yml ファイルに追加します。 これは、既定のスキームを使用して、シミュレーター用に、パッケージ化せずに iOS プロジェクトをビルドするための最小限のスニペットです。 自分のプロジェクトの構成に合わせて値を変更してください。 これらのオプションの詳細については、Xcode タスクを参照してください。

pool:
  vmImage: 'macos-latest'

steps:
- task: Xcode@5
  inputs:
    actions: 'build'
    scheme: ''
    sdk: 'iphoneos'
    configuration: 'Release'
    xcWorkspacePath: '**/*.xcodeproj/project.xcworkspace'
    xcodeVersion: 'default' # Options: 10, 11, 12, 13, 14, default, specifyPath

署名とプロビジョニング

Xcode アプリをデバイスで実行または App Store に発行するためには、署名してプロビジョニングする必要があります。 署名とプロビジョニングのプロセスでは、P12 署名証明書と 1 つ以上のプロビジョニング プロファイルにアクセスする必要があります。 Apple 証明書のインストールおよび Apple プロビジョニング プロファイルのインストール タスクを使用すると、ビルド中に Xcode でこれらを使用できるようになります。

詳細については、「モバイル アプリに署名する」を参照してください。

Carthage

プロジェクトにプライベート Carthage リポジトリで Carthage を使用する場合は、リポジトリにアクセスできるトークンの値を持つ GITHUB_ACCESS_TOKEN という名前の環境変数を設定することで、認証を設定できます。 この環境変数が Carthage で自動的に検出されて使用されます。

パイプライン YAML にシークレット トークンを直接追加しないでください。 代わりに、[変数] ペインでロックが有効になっている新しいパイプライン変数を作成して、この値を暗号化します。 「シークレット変数を設定する」を参照してください。

GITHUB_ACCESS_TOKEN 環境変数の値に myGitHubAccessToken という名前のシークレット変数を使用する例を次に示します。

- script: carthage update --platform iOS
  env:
    GITHUB_ACCESS_TOKEN: $(myGitHubAccessToken)

Azure でホストされるデバイス上でテストする

App Center テスト タスクを追加して、iOS と Android デバイスのホストされたラボでアプリをテストします。 App Center の無料試用版が必要です。これは、後で有料に変換する必要があります。

最初に App Center にサインアップします。

# App Center test v1
# Test app packages with Visual Studio App Center.
- task: AppCenterTest@1
  inputs:
    appFile: # string. Alias: app. Required. Binary application file path. 
    artifactsDirectory: '$(Build.ArtifactStagingDirectory)/AppCenterTest' # string. Alias: artifactsDir. Required. Artifacts directory. Default: $(Build.ArtifactStagingDirectory)/AppCenterTest.
  # Prepare Tests
    #prepareTests: true # boolean. Alias: enablePrepare. Prepare tests. Default: true.
    frameworkOption: 'appium' # 'appium' | 'espresso' | 'calabash' | 'uitest' | 'xcuitest'. Alias: framework. Required when enablePrepare = true. Test framework. Default: appium.
    #appiumBuildDirectory: # string. Alias: appiumBuildDir. Required when enablePrepare = true && framework = appium. Build directory. 
    #espressoBuildDirectory: # string. Alias: espressoBuildDir. Optional. Use when enablePrepare = true && framework = espresso. Build directory. 
    #espressoTestApkFile: # string. Alias: espressoTestApkPath. Optional. Use when enablePrepare = true && framework = espresso. Test APK path. 
    #calabashProjectDirectory: # string. Alias: calabashProjectDir. Required when enablePrepare = true && framework = calabash. Project directory. 
    #calabashConfigFile: # string. Optional. Use when enablePrepare = true && framework = calabash. Cucumber config file. 
    #calabashProfile: # string. Optional. Use when enablePrepare = true && framework = calabash. Profile to run. 
    #calabashSkipConfigCheck: false # boolean. Optional. Use when enablePrepare = true && framework = calabash. Skip Configuration Check. Default: false.
    #uiTestBuildDirectory: # string. Alias: uitestBuildDir. Required when enablePrepare = true && framework = uitest. Build directory. 
    #uitestStorePath: # string. Optional. Use when enablePrepare = true && framework = uitest. Store file. 
    #uiTestStorePassword: # string. Alias: uitestStorePass. Optional. Use when enablePrepare = true && framework = uitest. Store password. 
    #uitestKeyAlias: # string. Optional. Use when enablePrepare = true && framework = uitest. Key alias. 
    #uiTestKeyPassword: # string. Alias: uitestKeyPass. Optional. Use when enablePrepare = true && framework = uitest. Key password. 
    #uiTestToolsDirectory: # string. Alias: uitestToolsDir. Optional. Use when enablePrepare = true && framework = uitest. Test tools directory. 
    #signInfo: # string. Optional. Use when framework = calabash || framework = uitest. Signing information. 
    #xcUITestBuildDirectory: # string. Alias: xcuitestBuildDir. Optional. Use when enablePrepare = true && framework = xcuitest. Build directory. 
    #xcUITestIpaFile: # string. Alias: xcuitestTestIpaPath. Optional. Use when enablePrepare = true && framework = xcuitest. Test IPA path. 
    #prepareOptions: # string. Alias: prepareOpts. Optional. Use when enablePrepare = true. Additional options. 
  # Run Tests
    #runTests: true # boolean. Alias: enableRun. Run tests. Default: true.
    credentialsOption: 'serviceEndpoint' # 'serviceEndpoint' | 'inputs'. Alias: credsType. Required when enableRun = true. Authentication method. Default: serviceEndpoint.
    #serverEndpoint: # string. Required when enableRun = true && credsType = serviceEndpoint. App Center service connection. 
    #username: # string. Required when enableRun = true && credsType = inputs. App Center username. 
    #password: # string. Required when enableRun = true && credsType = inputs. App Center password. 
    appSlug: # string. Required when enableRun = true. App slug. 
    devices: # string. Required when enableRun = true. Devices. 
    #series: 'master' # string. Optional. Use when enableRun = true. Test series. Default: master.
    #dsymDirectory: # string. Alias: dsymDir. Optional. Use when enableRun = true. dSYM directory. 
    localeOption: 'en_US' # 'da_DK' | 'nl_NL' | 'en_GB' | 'en_US' | 'fr_FR' | 'de_DE' | 'ja_JP' | 'ru_RU' | 'es_MX' | 'es_ES' | 'user'. Alias: locale. Required when enableRun = true. System language. Default: en_US.
    #userDefinedLocale: # string. Optional. Use when enableRun = true && locale = user. Other locale. 
    #loginOptions: # string. Alias: loginOpts. Optional. Use when enableRun = true && credsType = inputs. Additional options for login. 
    #runOptions: # string. Alias: runOpts. Optional. Use when enableRun = true. Additional options for run. 
    #skipWaitingForResults: false # boolean. Alias: async. Optional. Use when enableRun = true. Do not wait for test result. Default: false.
  # Advanced
    #cliFile: # string. Alias: cliLocationOverride. App Center CLI location. 
    #showDebugOutput: false # boolean. Alias: debug. Enable debug output. Default: false.

ビルド レコードを使用して成果物を保持する

ファイルのコピーおよびビルド成果物の発行タスクを追加して、ビルド レコードを含む IPA を格納するか、後続のパイプラインでテストおよびデプロイします。 成果物に関するページを参照してください。

- task: CopyFiles@2
  inputs:
    contents: '**/*.ipa'
    targetFolder: '$(build.artifactStagingDirectory)'
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

配置

App Center

App Center 配布タスクを追加して、テスト担当者やベータ ユーザーのグループにアプリを配布するか、アプリケーションを Intune や Apple App Store に昇格します。 無料の App Center アカウントが必要です (支払いは不要)。

# App Center distribute v3
# Distribute app builds to testers and users via Visual Studio App Center.
- task: AppCenterDistribute@3
  inputs:
    serverEndpoint: # string. Required. App Center service connection. 
    appSlug: # string. Required. App slug. 
    appFile: # string. Alias: app. Required. Binary file path. 
    #buildVersion: # string. Build version. 
    releaseNotesOption: 'input' # 'input' | 'file'. Alias: releaseNotesSelection. Required. Create release notes. Default: input.
    releaseNotesInput: # string. Required when releaseNotesSelection = input. Release notes. 
    #releaseNotesFile: # string. Required when releaseNotesSelection = file. Release notes file. 
    #isMandatory: false # boolean. Require users to update to this release. Default: false.
    destinationType: 'groups' # 'groups' | 'store'. Required. Release destination. Default: groups.
    #distributionGroupId: # string. Alias: destinationGroupIds. Optional. Use when destinationType = groups. Destination IDs. 
    #destinationStoreId: # string. Required when destinationType = store. Destination ID. 
    #isSilent: # boolean. Optional. Use when destinationType = groups. Do not notify testers. Release will still be available to install. 
  # Symbols
    #symbolsOption: 'Apple' # 'Apple' | 'Android' | 'UWP'. Alias: symbolsType. Symbols type. Default: Apple.
    #symbolsPath: # string. Optional. Use when symbolsType == AndroidNative || symbolsType = Windows. Symbols path. 
    #appxsymPath: # string. Optional. Use when symbolsType = UWP. Symbols path (*.appxsym). 
    #symbolsDsymFiles: # string. Alias: dsymPath. Optional. Use when symbolsType = Apple. dSYM path. 
    #symbolsMappingTxtFile: # string. Alias: mappingTxtPath. Optional. Use when symbolsType = Android. Mapping file. 
    #nativeLibrariesPath: # string. Optional. Use when symbolsType == Android. Native Library File Path. 
    #symbolsIncludeParentDirectory: # boolean. Alias: packParentFolder. Optional. Use when symbolsType = Apple. Include all items in parent folder.

Apple App Store

Apple App Store 拡張機能をインストールし、次のタスクを使用して、App Store との対話を自動化します。 既定では、これらのタスクは構成したサービス接続を使用して、Apple に対して認証されます。

リリース

App Store リリース タスクを追加して、App Store にある既存の iOS TestFlight ベータ アプリまたは運用アプリへの更新プログラムのリリースを自動化します。

Apple の 2 要素認証でこのタスクを使用する場合の制限事項を参照してください。Apple 認証は地域固有であり、fastlane セッション トークンはすぐに期限切れになり、再作成および再構成する必要があります。

- task: AppStoreRelease@1
  displayName: 'Publish to the App Store TestFlight track'
  inputs:
    serviceEndpoint: 'My Apple App Store service connection' # This service connection must be added by you
    appIdentifier: com.yourorganization.testapplication.etc
    ipaPath: '$(build.artifactstagingdirectory)/**/*.ipa'
    shouldSkipWaitingForProcessing: true
    shouldSkipSubmission: true

昇格

App Store 昇格タスクを追加して、iTunes Connect から以前に送信したアプリの App Store への昇格を自動化します。

- task: AppStorePromote@1
  displayName: 'Submit to the App Store for review'
  inputs:
    serviceEndpoint: 'My Apple App Store service connection' # This service connection must be added by you
    appIdentifier: com.yourorganization.testapplication.etc
    shouldAutoRelease: false