モバイルアプリエンジニアの山下(@yamshta)です。
Apple IDの2FAが必須となり暫く経ちましたが、皆さんのCIは問題なく動いたでしょうか? LCLの環境では案の定 Bitrise上で動かしているFastlaneのplistで6digitコードを聞かれてしまいワークフローが失敗する事象が発生しました。
この問題は2FAを設定してない別のApple IDを利用することで回避することが可能ですが、対応当時は既存のアカウントを使う別の方法で対応しました。
リリースワークフローを動かすとpilotで失敗してしまう
2FAを有効にした後、ワークフロー実行時に以下の6digitコードが聞かれるようになりました。
[10:09:29]:-------------------
[10:09:29]:--- Step: pilot ---
[10:09:29]:-------------------
[10:09:31]:Login to App Store Connect (xxxxx@xxx.com)
[10:09:31]:Session loaded from environment variable is not valid. Continuing with normal login.
Two-factor Authentication (6 digits code) is enabled for account 'xxxxx@xxx.com'
More information about Two-factor Authentication: https://support.apple.com/en-us/HT204915
If you're running this in a non-interactive session (e.g. server or CI)
check out https://github.com/fastlane/fastlane/tree/master/spaceship#2-step-verification
(Input `sms` to escape this prompt and select a trusted phone number to send the code as a text message)
Please enter the 6 digit code:
もちろんCI上で動かしているので入力することはできません。 ログに出力されている、以下のページを参考に対応しました。
check out https://github.com/fastlane/fastlane/tree/master/spaceship#2-step-verification
手順
1. Application specific password を環境変数に追加
appleid.apple.com/account/manage で Application specific password を作成し、BitriseのSecretsに FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD
というKey名で追加します。
2. spaceauthでApple IDへのログインセッションを取得して環境変数に追加
細かく分けるとこの中で2つやることがあります
- spaceauthでApple IDへのログインセッションを取得する
- 取得したセッション情報を環境変数に追加する
まずは、spaceauthでApple IDへのログインセッションを取得します。 こちらはCIではなく、ローカル環境(自身のPC)で実行します。
$ fastlane spaceauth -u xxxxx@xxx.com
[✔] 🚀
[10:29:51]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
Logging into to App Store Connect (xxxxx@xxx.com)...
Available session is not valid any more. Continuing with normal login.
Two-factor Authentication (6 digits code) is enabled for account 'xxxxx@xxx.com'
More information about Two-factor Authentication: https://support.apple.com/en-us/HT204915
If you're running this in a non-interactive session (e.g. server or CI)
check out https://github.com/fastlane/fastlane/tree/master/spaceship#2-step-verification
(Input `sms` to escape this prompt and select a trusted phone number to send the code as a text message)
Please enter the 6 digit code:
012345
Requesting session...
Successfully logged in to App Store Connect
---
Pass the following via the FASTLANE_SESSION environment variable:
---\n- !ruby/object:HTTP::Cookie\n name: myacinfo\n value: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n domain: apple.com\n for_domain: true\n path: "/"\n secure: true\n httponly: true\n expires: \n max_age: \n created_at: 2019-05-29 10:30:17.654002000 +09:00\n accessed_at: 2019-05-29 10:30:17.660725000 +09:00\n- !ruby/object:HTTP::Cookie\n name: dqsid\n value: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n domain: olympus.itunes.apple.com\n for_domain: false\n path: "/"\n secure: true\n httponly: true\n expires: \n max_age: 1800\n created_at: &1 2019-05-29 10:30:18.404963000 +09:00\n accessed_at: *1\n
Example:
export FASTLANE_SESSION='---\n- !ruby/object:HTTP::Cookie\n name: myacinfo\n value: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n domain: apple.com\n for_domain: true\n path: "/"\n secure: true\n httponly: true\n expires: \n max_age: \n created_at: 2019-05-29 10:30:17.654002000 +09:00\n accessed_at: 2019-05-29 10:30:17.660725000 +09:00\n- !ruby/object:HTTP::Cookie\n name: dqsid\n value: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n domain: olympus.itunes.apple.com\n for_domain: false\n path: "/"\n secure: true\n httponly: true\n expires: \n max_age: 1800\n created_at: &1 2019-05-29 10:30:18.404963000 +09:00\n accessed_at: *1\n'
🙄 Should fastlane copy the cookie into your clipboard, so you can easily paste it? (y/n)
y
Successfully copied text into your clipboard 🎨
これで取得できたので取得したセッション情報を環境変数に追加します。
こちらは FASTLANE_SESSION
というKey名で追加します。
以上で再度ワークフローを実行すると無事に成功すると思います。 但し、このやり方はログインセッションが切れる度に発生するため、やはり冒頭で触れたように別のApple IDを利用するようにした方がよいです。
最後に
LCLではCI/CDにも興味があり、可能な限り自動化して手作業を無くしたい!という意識を持ったエンジニアを募集しています!ご興味のある方は、お気軽にご連絡ください!