使用fastlane自動化部署APP

fastlane運行所需要的環境:

  1. OS X 10.9以上
  2. Ruby 2.0 以上
  3. Xcode
  4. 擁有一個開發者賬號

因為fastlane其實是一個Ruby腳本的集合,你必須安裝正確的Ruby版本。可用一下命令確認

安裝

1、ruby -v 查看ruby版本
2、然后檢查Xcode命令行工具(CLT)是否安裝。在終端中輸入命令:

xcode-select --install

如果已經安裝,則會報一下錯誤

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

如果沒安裝,終端會開始安裝CLT。

3、通過rubygem安裝fastlane

sudo gem install fastlane -v 2.57.2 --verbose

初始化

打開終端,cd到你的工程目錄,然后執行fastlane init
運行結果如下

fastlane init
[15:35:29]: Seems like launching fastlane takes a while - please run
[15:35:29]:
[15:35:29]: $ [sudo] gem cleanup
[15:35:29]:
[15:35:29]: to uninstall outdated gems and make fastlane launch faster
[15:35:29]: Alternatively it's recommended to start using a Gemfile to lock your dependencies
[15:35:29]: To get started with a Gemfile, run
[15:35:29]:
[15:35:29]: $ bundle init
[15:35:29]: $ echo 'gem "fastlane"' >> Gemfile
[15:35:29]: $ bundle install
[15:35:29]:
[15:35:29]: After creating the Gemfile and Gemfile.lock, commit those files into version control
[15:35:29]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[15:35:32]: Detected iOS/Mac project in current directory...
[15:35:32]: This setup will help you get up and running in no time.
[15:35:32]: fastlane will check what tools you're already using and set up
[15:35:32]: the tool automatically for you. Have fun!
[15:35:32]: Created new folder './fastlane'.
[15:35:32]: $ xcodebuild -list -project ./JenkinsDemo.xcodeproj
2017-12-07 15:35:33.629 xcodebuild[39937:3765993] [MT] PluginLoading: Required plug-in compatibility UUID DF11C142-1584-4A99-87AC-1925D5F5652A for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/FuzzyAutocomplete.xcplugin' not present in DVTPlugInCompatibilityUUIDs
[15:35:34]: $ xcodebuild -showBuildSettings -scheme JenkinsDemo -project ./JenkinsDemo.xcodeproj
2017-12-07 15:35:34.373 xcodebuild[39940:3766165] [MT] PluginLoading: Required plug-in compatibility UUID DF11C142-1584-4A99-87AC-1925D5F5652A for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/FuzzyAutocomplete.xcplugin' not present in DVTPlugInCompatibilityUUIDs
[15:35:35]: Your Apple ID (e.g. fastlane@krausefx.com): 這里是你的Apple ID
[15:35:49]: Verifying that app is available on the Apple Developer Portal and iTunes Connect...
[15:35:49]: Starting login with user '這里是你的Apple ID'

+----------------+--------------------------------------+
|                    Detected Values                    |
+----------------+--------------------------------------+
| Apple ID       | 這里是你的Apple ID                   |
| App Name       | JenkinsDemo                          |
| App Identifier | com.jenkin.Debug                     |
| Project        | /Users/xyj/Desktop/test/JenkinsDemo  |
|                | .xcodeproj                           |
+----------------+--------------------------------------+

[15:36:00]: Please confirm the above values (y/n)
y
[15:36:11]: Created new file './fastlane/Appfile'. Edit it to manage your preferred app metadata information.
[15:36:11]: Loading up 'deliver', this might take a few seconds
[15:36:11]: Login to iTunes Connect (it_ios@ixinyongjia.com)
[15:36:14]: Login successful

+--------------------------------------+------------------------+
|                    deliver 2.68.2 Summary                     |
+--------------------------------------+------------------------+
| run_precheck_before_submit           | false                  |
| screenshots_path                     | ./fastlane/screenshots |
| metadata_path                        | ./fastlane/metadata    |
| username                             | 這里是你的Apple ID     |
| app_identifier                       | com.jenkin.Debug       |
| edit_live                            | false                  |
| platform                             | ios                    |
| skip_binary_upload                   | false                  |
| skip_screenshots                     | false                  |
| skip_metadata                        | false                  |
| skip_app_version_update              | false                  |
| force                                | false                  |
| submit_for_review                    | false                  |
| automatic_release                    | false                  |
| dev_portal_team_id                   | 99WG99HF75             |
| overwrite_screenshots                | false                  |
| precheck_default_rule_level          | warn                   |
| ignore_language_directory_validatio  | false                  |
| n                                    |                        |
| precheck_include_in_app_purchases    | true                   |
+--------------------------------------+------------------------+

[15:36:17]: Writing to './fastlane/metadata/zh-Hans/description.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/keywords.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/release_notes.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/support_url.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/marketing_url.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/promotional_text.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/name.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/subtitle.txt'
[15:36:17]: Writing to './fastlane/metadata/zh-Hans/privacy_url.txt'
[15:36:17]: Writing to './fastlane/metadata/copyright.txt'
[15:36:17]: Writing to './fastlane/metadata/primary_category.txt'
[15:36:17]: Writing to './fastlane/metadata/secondary_category.txt'
[15:36:17]: Writing to './fastlane/metadata/primary_first_sub_category.txt'
[15:36:17]: Writing to './fastlane/metadata/primary_second_sub_category.txt'
[15:36:17]: Writing to './fastlane/metadata/secondary_first_sub_category.txt'
[15:36:17]: Writing to './fastlane/metadata/secondary_second_sub_category.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/trade_name.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/address_line1.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/city_name.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/country.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/postal_code.txt'
[15:36:17]: Writing to './fastlane/metadata/trade_representative_contact_information/is_displayed_on_app_store.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/first_name.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/last_name.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/phone_number.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/email_address.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/demo_user.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/demo_password.txt'
[15:36:17]: Writing to './fastlane/metadata/review_information/notes.txt'
[15:36:17]: Successfully created new configuration files.
[15:36:17]: Downloading all existing screenshots...
[15:36:19]: Successfully downloaded all existing screenshots
[15:36:19]: Successfully created new Deliverfile at path './fastlane/Deliverfile'
[15:36:19]: 'snapshot' not enabled.
[15:36:19]: 'cocoapods' not enabled.
[15:36:19]: 'carthage' not enabled.
[15:36:19]: Created new file './fastlane/Fastfile'. Edit it to manage your own deployment lanes.
[15:36:19]: fastlane will collect the number of errors for each action to detect integration issues
[15:36:19]: No sensitive/private information will be uploaded
[15:36:19]: Learn more at https://github.com/fastlane/fastlane#metrics
[15:36:19]: Successfully finished setting up fastlane

上述過程可能要輸密碼,將Apple ID的密碼正確輸入就可以了。

初始化完成之后,工程目錄下就多了個fastlane文件夾,內容如下


sdf.png

這里肯定會被創建的是Appfile和Fastfile。如果Deliverfile,screenshots和metadata目錄沒被創建,可以運行deliver init來創建。

  • Appfile :用來存儲一些公共信息,比如app_identifierapple_idteam_iditc_team_id等。

  • Fastfile:用來定義所有的lane任務
    一開始的內容如下:

# Customize this file, documentation can be found here:
# https://docs.fastlane.tools/actions/
# All available actions: https://docs.fastlane.tools/actions
# can also be listed using the `fastlane actions` command

# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`

# If you want to automatically update fastlane if a new version is available:
# 自動更新fastlane
# update_fastlane

# This is the minimum version number required.
# Update this, if you use features of a newer version
# 需要的fastlane的最小版本,在每次執行之后會檢查是否有新版本,如果有會在最后末尾追加新版本提醒
fastlane_version "2.68.2"

# 默認使用平臺是ios,也就是說可以定義多個平臺
default_platform :ios

# 執行所有的lane語句之前要做的事情,
platform :ios do
  before_all do
    # 自定義變量
    # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
    # 是否使用cocoapods構建項目
    # cocoapods
    # carthage
  end

  # 跑一遍測試
  desc "Runs all the tests"
  lane :test do
    run_tests
  end

  # 提交一個新的beta版本到 Apple TestFlight
  desc "Submit a new Beta Build to Apple TestFlight"
  desc "This will also make sure the profile is up to date"
  lane :beta do
    # match(type: "appstore") # more information: https://codesigning.guide
    build_app(scheme: "JenkinsDemo") # more options available
    upload_to_testflight

    # sh "your_script.sh"
    # You can also use other beta testing services here (run `fastlane actions`)
  end

  # 部署一個新版本到App store
  desc "Deploy a new version to the App Store"
  lane :release do
    # sync_code_signing(type: "appstore")
    capture_screenshots
    build_app(scheme: "JenkinsDemo") # Build your app - more options available
    upload_to_app_store(force: true)
    # frame_screenshots
  end

  # 你也可以定義自己的lane
  # You can define as many lanes as you want

  # 執行lane之后的回調
  after_all do |lane|
    # This block is called, only if the executed lane was successful

    # slack(
    #   message: "Successfully deployed new App Update."
    # )
  end
  
  # 流程異常,結束流程并輸出錯誤信息
  error do |lane, exception|
    # slack(
    #   message: exception.message,
    #   success: false
    # )
  end
end


# More information about multiple platforms in fastlane: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
# All available actions: https://docs.fastlane.tools/actions

# fastlane reports which actions are used. No personal data is recorded.
# Learn more at https://docs.fastlane.tools/#metrics

在 fastlane 這個大家庭中,主要但包括不盡于下列工具:

  • scan 自動化測試工具,很好的封裝了 Unit Test
  • sigh: 創建、更新、下載和修復 provisioning profiles。
  • match 同步團隊每個人的證書和 Provision file 的超贊工具
  • cert: 自動創建和維護 iOS 代碼簽名證書。
  • gym: 創建和打包 iOS app。
  • deliver: 上傳屏幕截圖、元數據和 App 到 App 商店。
  • produce: 創建可用于 iTunes Connect 和 Apple Developer Portal 的 iOS app。
  • snapshot: 自動將 App屏幕截圖本地化到每種設備上。
  • frameit: 將屏幕截圖適配到適當的設備屏幕大小。
  • PEM: 自動創建和更新 Push 通知的 profile。

fastlane 實戰

一、打一個測試包,并上傳到蒲公英交付測試.

1、創建一個匹配開發證書的lane

說明:其中一個lane就是一個任務,里面是一個個的action組成的工作流

打開fastlane文件夾下的Fastfile文件(最好用xcode打開)。

創建一個lane:格式如下

desc "匹配開發證書"
lane :matchDev do
match(type: "development", keychain_password: "git")
end

說明:主要用到了match工具,其中type是指定環境,keychain_password,服務器鑰匙串密碼,match工具當然不止這些參數,想了解更多參數可以在終端執行fastlane action match,或者fastlane match --help來查看文檔。

創建好了,在終端執行如下:

fastlane matchDev
[17:55:34]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[17:55:38]: -------------------------------------------------
[17:55:38]: --- Step: Verifying required fastlane version ---
[17:55:38]: -------------------------------------------------
[17:55:38]: Your fastlane version 2.68.2 matches the minimum requirement of 2.68.2  ?
[17:55:38]: ------------------------------
[17:55:38]: --- Step: default_platform ---
[17:55:38]: ------------------------------
[17:55:38]: Driving the lane 'ios matchDev' ??
[17:55:38]: -------------------
[17:55:38]: --- Step: match ---
[17:55:38]: -------------------

+-----------------------+------------------------+
|            Summary for match 2.68.2            |
+-----------------------+------------------------+
| type                  | development            |
| keychain_password     | ********               |
| git_branch            | master                 |
| app_identifier        | com.jenkin.Debug       |
| username              | 這里顯示的是開發者賬號 |
| keychain_name         | login.keychain         |
| readonly              | false                  |
| team_id               | 99WG99HF75             |
| verbose               | false                  |
| force                 | false                  |
| skip_confirmation     | false                  |
| shallow_clone         | false                  |
| clone_branch_directly | false                  |
| force_for_new_devices | false                  |
| skip_docs             | false                  |
| platform              | ios                    |
+-----------------------+------------------------+

[17:55:38]: To not be asked about this value, you can specify it using 'git_url'
[17:55:38]: URL to the git repo containing all the certificates: git@172.16.11.154:repositories/test.git
[17:57:00]: Cloning remote git repo...
[17:57:00]: If cloning the repo takes too long, you can use the `clone_branch_directly` option in match.
[17:57:00]: ??  Successfully decrypted certificates repo
[17:57:00]: Verifying that the certificate and profile are still valid on the Dev Portal...
[17:57:05]: Couldn't find a valid code signing identity in the git repo for development... creating one for you now

+-------------------+------------------------------------------------+
|                      Summary for cert 2.68.2                       |
+-------------------+------------------------------------------------+
| development       | true                                           |
| force             | true                                           |
| username          | 這里顯示的是開發者賬號                         |
| team_id           | 99WG99HF75                                     |
| keychain_path     | /Users/xyj/Library/Keychains/login.keychain-db |
| keychain_password | ********                                       |
| platform          | ios                                            |
+-------------------+------------------------------------------------+

[17:57:05]: Starting login with user '這里顯示的是開發者賬號'
[17:57:08]: Successfully logged in
[17:57:15]: Successfully generated FQV3SGXTZ9 which was imported to the local machine.
[17:57:17]: Verifying the certificate is properly installed locally...
[17:57:17]: Successfully installed certificate FQV3SGXTZ9

+-------------------------------------+------------------------------------+
|                         Summary for sigh 2.68.2                          |
+-------------------------------------+------------------------------------+
| app_identifier                      | com.jenkin.Debug                   |
| username                            | 這里顯示的是開發者賬號             |
| force                               | true                               |
| cert_id                             | FQV3SGXTZ9                         |
| provisioning_name                   | match Development com.jenkin.Debug |
| ignore_profiles_with_different_name | true                               |
| team_id                             | 99WG99HF75                         |
| platform                            | ios                                |
| development                         | true                               |
| adhoc                               | false                              |
| skip_install                        | false                              |
| skip_fetch_profiles                 | false                              |
| skip_certificate_verification       | false                              |
| readonly                            | false                              |
+-------------------------------------+------------------------------------+

[17:57:19]: Starting login with user '這里顯示的是開發者賬號'
[17:57:21]: Successfully logged in
[17:57:21]: Fetching profiles...
[17:57:22]: Verifying certificates...
[17:57:25]: No existing profiles found, that match the certificates you have installed locally! Creating a new provisioning profile for you
[17:57:32]: The name 'match Development com.jenkin.Debug' is already taken, using another one.
[17:57:32]: Creating new provisioning profile for 'com.jenkin.Debug' with name 'match Development com.jenkin.Debug 1512640652' for 'ios' platform
[17:57:37]: Downloading provisioning profile...
[17:57:38]: Successfully downloaded provisioning profile...
[17:57:38]: Installing provisioning profile...
/var/folders/w9/q16q5ckx2k3b3vmskgh3ksx00000gn/T/d20171207-41012-161tif9/profiles/development/Development_com.jenkin.Debug.mobileprovision
[17:57:38]: Installing provisioning profile...
[17:57:40]: ??  Successfully encrypted certificates repo
[17:57:40]: Pushing changes to remote git repo...

+---------------------+------------------------------------------------+---------------------------------------------------------+
|                                                 Installed Provisioning Profile                                                 |
+---------------------+------------------------------------------------+---------------------------------------------------------+
| Parameter           | Environment Variable                           | Value                                                   |
+---------------------+------------------------------------------------+---------------------------------------------------------+
| App Identifier      |                                                | com.jenkin.Debug                                        |
| Type                |                                                | development                                             |
| Platform            |                                                | ios                                                     |
| Profile UUID        | sigh_com.jenkin.Debug_development              | 8d811267-9a90-4186-84ff-849270910564                    |
| Profile Name        | sigh_com.jenkin.Debug_development_profile-name | match Development com.jenkin.Debug 1512640652           |
| Profile Path        | sigh_com.jenkin.Debug_development_profile-path | /Users/xyj/Library/MobileDevice/Provisioning            |
|                     |                                                | Profiles/8d811267-9a90-4186-84ff-849270910564.mobilepr  |
|                     |                                                | ovision                                                 |
| Development Team ID | sigh_com.jenkin.Debug_development_team-id      | 99WG99HF75                                              |
+---------------------+------------------------------------------------+---------------------------------------------------------+

[17:57:40]: All required keys, certificates and provisioning profiles are installed ??
[17:57:40]: Setting Provisioning Profile type to 'development'

+------+-------------------------------------+-------------+
|                     fastlane summary                     |
+------+-------------------------------------+-------------+
| Step | Action                              | Time (in s) |
+------+-------------------------------------+-------------+
| 1    | Verifying required fastlane version | 0           |
| 2    | default_platform                    | 0           |
| 3    | match                               | 122         |
+------+-------------------------------------+-------------+

[17:57:40]: fastlane.tools finished successfully ??

這里主要說一下幾點:

1、git_url:git_url是git服務器地址,我沒指定git_url, ,匹配證書的時候,要求我輸入服務器地址。輸入完成后就會clone git服務器的代碼,

2、驗證證書:keychain_password就是為這步而存在的,這里由于我沒在git服務器下載證書,所以沒找到,但是fastlane為我重新創建了一個

3、描述文件:其實我已經在證書(之前就創建的證書)上生成了描述文件,但是fastlane重新生成了證書,所以他沒找到描述文件,又自動給我重新生成了一個。

上面三種情況是fastlane的正常流程,但是我之前都創建好了,也就是說他現在的操作不是我想看到的。接下來我們將匹配開發證書的lane改成下面這樣

desc "匹配開發證書"
lane :matchDev do
match(type: "development", keychain_password: "git", git_url: "git@172.16.11.154:repositories/test.git")
end

并且登錄開發者賬號將新生成的證書和描述文件都刪掉,登錄git服務器,將證書下載并安裝好

再次在終端運行,結果如下:

fastlane matchDev
[11:12:18]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[11:12:21]: -------------------------------------------------
[11:12:21]: --- Step: Verifying required fastlane version ---
[11:12:21]: -------------------------------------------------
[11:12:21]: Your fastlane version 2.68.2 matches the minimum requirement of 2.68.2  ?
[11:12:21]: ------------------------------
[11:12:21]: --- Step: default_platform ---
[11:12:21]: ------------------------------
[11:12:21]: Driving the lane 'ios matchDev' ??
[11:12:21]: -------------------
[11:12:21]: --- Step: match ---
[11:12:21]: -------------------

+-----------------------+-----------------------------------------+
|                    Summary for match 2.68.2                     |
+-----------------------+-----------------------------------------+
| type                  | development                             |
| git_url               | git@172.16.11.154:repositories/test.git |
| force                 | true                                    |
| git_branch            | master                                  |
| app_identifier        | com.jenkin.Debug                        |
| username              | 這里顯示的是開發者賬號                  |
| keychain_name         | login.keychain                          |
| readonly              | false                                   |
| team_id               | 99WG99HF75                              |
| verbose               | false                                   |
| skip_confirmation     | false                                   |
| shallow_clone         | false                                   |
| clone_branch_directly | false                                   |
| force_for_new_devices | false                                   |
| skip_docs             | false                                   |
| platform              | ios                                     |
+-----------------------+-----------------------------------------+

[11:12:21]: Cloning remote git repo...
[11:12:21]: If cloning the repo takes too long, you can use the `clone_branch_directly` option in match.
[11:12:22]: ??  Successfully decrypted certificates repo
[11:12:22]: Verifying that the certificate and profile are still valid on the Dev Portal...
[11:12:26]: Installing certificate...

+-------------------+----------------------------------------------------------+
|                            Installed Certificate                             |
+-------------------+----------------------------------------------------------+
| User ID           | BED2DYAVHS                                               |
| Common Name       | 這里顯示證書名字
|
| Organisation Unit | 99WG99HF75                                               |
| Organisation      | ******** |
| Country           | US                                                       |
| Start Datetime    | Dec  8 02:58:55 2017 GMT                                 |
| End Datetime      | Dec  8 02:58:55 2018 GMT                                 |
+-------------------+----------------------------------------------------------+


+-------------------------------------+------------------------------------+
|                         Summary for sigh 2.68.2                          |
+-------------------------------------+------------------------------------+
| app_identifier                      | com.jenkin.Debug                   |
| username                            | 這里顯示的是開發者賬號             |
| force                               | true                               |
| cert_id                             | SP54MR68FC                         |
| provisioning_name                   | match Development com.jenkin.Debug |
| ignore_profiles_with_different_name | true                               |
| team_id                             | 99WG99HF75                         |
| platform                            | ios                                |
| development                         | true                               |
| adhoc                               | false                              |
| skip_install                        | false                              |
| skip_fetch_profiles                 | false                              |
| skip_certificate_verification       | false                              |
| readonly                            | false                              |
+-------------------------------------+------------------------------------+

[11:12:27]: Starting login with user '這里顯示的是開發者賬號'
[11:12:30]: Successfully logged in
[11:12:30]: Fetching profiles...
[11:12:31]: Verifying certificates...
[11:12:32]: Found 1 matching profile(s)
[11:12:32]: Recreating the profile
[11:12:34]: Creating new provisioning profile for 'com.jenkin.Debug' with name 'match Development com.jenkin.Debug' for 'ios' platform
[11:12:35]: Downloading provisioning profile...
[11:12:35]: Successfully downloaded provisioning profile...
[11:12:36]: Installing provisioning profile...
/var/folders/w9/q16q5ckx2k3b3vmskgh3ksx00000gn/T/d20171208-50529-1yh4aue/profiles/development/Development_com.jenkin.Debug.mobileprovision
[11:12:36]: Installing provisioning profile...
[11:12:37]: ??  Successfully encrypted certificates repo
[11:12:37]: Pushing changes to remote git repo...

+---------------------+------------------------------------+------------------------------------+
|                                Installed Provisioning Profile                                 |
+---------------------+------------------------------------+------------------------------------+
| Parameter           | Environment Variable               | Value                              |
+---------------------+------------------------------------+------------------------------------+
| App Identifier      |                                    | com.jenkin.Debug                   |
| Type                |                                    | development                        |
| Platform            |                                    | ios                                |
| Profile UUID        | sigh_com.jenkin.Debug_development  | 63075bad-3ee8-449e-9ebb-251c50ea7  |
|                     |                                    | f0c                                |
| Profile Name        | sigh_com.jenkin.Debug_development  | match Development                  |
|                     | _profile-name                      | com.jenkin.Debug                   |
| Profile Path        | sigh_com.jenkin.Debug_development  | /Users/xyj/Library/MobileDevice/P  |
|                     | _profile-path                      | rovisioning                        |
|                     |                                    | Profiles/63075bad-3ee8-449e-9ebb-  |
|                     |                                    | 251c50ea7f0c.mobileprovision       |
| Development Team ID | sigh_com.jenkin.Debug_development  | 99WG99HF75                         |
|                     | _team-id                           |                                    |
+---------------------+------------------------------------+------------------------------------+

[11:12:37]: All required keys, certificates and provisioning profiles are installed ??
[11:12:37]: Setting Provisioning Profile type to 'development'

+------+------------------------------+-------------+
|                 fastlane summary                  |
+------+------------------------------+-------------+
| Step | Action                       | Time (in s) |
+------+------------------------------+-------------+
| 1    | Verifying required fastlane  | 0           |
|      | version                      |             |
| 2    | default_platform             | 0           |
| 3    | match                        | 16          |
+------+------------------------------+-------------+

[11:12:37]: fastlane.tools finished successfully ??

完成上面的步驟后,clone下你的代碼。工程下面多了兩個文件夾certsprofiles

  • certs文件夾下面包含一個.cer文件和一個.p12文件。命名都是以證書id,這兩個文件分別用于自己開發和授權團隊的小伙伴開發的。
  • profiles文件夾下面存放的是描述文件

當你的倉庫里面沒這兩個,fastlane會為你重新創建證書和描述文件。如果有了。那就是上面這種情況,fastlane會直接幫你匹配好證書和描述文件。

至此,創建一個匹配開發證書的lane就算完成了。

2.創建一個打測試包的lane

創建一個lane,格式如下:

desc "打測試包"
  desc "This will also make sure the profile is up to date"
  lane :expIpa do
  gym(clean: true, export_method: "development", configuration: "Debug")
  end

這里主要涉及的工具為gym,命令包含clean,export_method,configuration三個參數,分別的含義為編譯之前是否clean、導出archive包的方式、編譯哪個configuration。

想了解更多參數,可在終端輸入fastlane action gymfastlane gym --help查看文檔。

執行上面的命令后,在工程目錄下可以看到導出的ipa包。沒指定名字的話,ipa包的名字就是你的工程名。

3.創建一個上傳到測試包到第三方分發平臺的lane,這里以蒲公英為例

上傳測試包到蒲公英、firim等第三方平臺,都要到相應的第三方平臺注冊賬號,這些平臺一般都會制作fastlane的插件來支持fastlane上傳測試包,這里做簡單的介紹,查看詳細文檔請查看蒲公英官方文檔

1、查看、安裝fastlane插件

在終端輸入 fastlane search_plugins可以查看當前版本所有可用的插件,可以在里面看到pgyer插件,想知道如何使用請異步蒲公英官網查看。

安裝pgyer插件:

fastlane add_plugin pgyer

安裝完成后你就可以使用fastlane action pgyer來查看相關的參數以及使用了。

官網給出的例子是:

lane :beta do
  gym(export_method: "ad-hoc")
  pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e")
end

以上的 api_key 和 user_key,請開發者在自己賬號(蒲公英)下的 應用管理 - App概述 - API 中可以找到,并替換到以上相應的位置。

上面,我們已經打好測試包了,下面我們就上傳測試到蒲公英。

lane如下:

desc "上傳到蒲公英"
lane :uploadPGY do
pgyer(api_key: "75284caf4b30813b45b557ca7d121b2d", user_key: "fa8d179bb6b6cf382931ee2e487e2321",ipa: "JenkinsDemo.ipa")
end

執行結果如下:

?  test git:(master) ? fastlane uploadPGY
+-----------------------+---------+--------+
|               Used plugins               |
+-----------------------+---------+--------+
| Plugin                | Version | Action |
+-----------------------+---------+--------+
| fastlane-plugin-pgyer | 0.2.1   | pgyer  |
+-----------------------+---------+--------+

[10:48:01]: -------------------------------------------------
[10:48:01]: --- Step: Verifying required fastlane version ---
[10:48:01]: -------------------------------------------------
[10:48:01]: Your fastlane version 2.68.2 matches the minimum requirement of 2.68.2  ?
[10:48:01]: ------------------------------
[10:48:01]: --- Step: default_platform ---
[10:48:01]: ------------------------------
[10:48:01]: Driving the lane 'ios uploadPGY' ??
[10:48:01]: -------------------
[10:48:01]: --- Step: pgyer ---
[10:48:01]: -------------------
[10:48:01]: The pgyer plugin is working.
[10:48:01]: build_file: JenkinsDemo.ipa
[10:48:01]: Start upload JenkinsDemo.ipa to pgyer...
[10:48:45]: Upload success. Visit this URL to see: https://www.pgyer.com/LnYN

+------+-------------------------------------+-------------+
|                     fastlane summary                     |
+------+-------------------------------------+-------------+
| Step | Action                              | Time (in s) |
+------+-------------------------------------+-------------+
| 1    | Verifying required fastlane version | 0           |
| 2    | default_platform                    | 0           |
| 3    | pgyer                               | 43          |
+------+-------------------------------------+-------------+

[10:48:45]: fastlane.tools finished successfully ??

可以看到,上傳成功后會給出一個鏈接,測試只需要打開這個鏈接就能掃碼安裝測試包了

小結:

上面幾個步驟,其實是可以在一個lane里面完成的。我改進后的lane如下

desc "打測試包并上傳蒲公英"
lane :dev do
# 調用匹配開發證書的lane
matchDev
expIpa
uploadPGY
end

當然,你可以這樣:

desc "打測試包并上傳蒲公英"
lane :dev do
match(type: "development", git_url: "git@172.16.11.154:repositories/test.git")
gym(clean: true, export_method: "development", configuration: "Debug")
pgyer(api_key: "75284caf4b30813b45b557ca7d121b2d", user_key: "fa8d179bb6b6cf382931ee2e487e2321",ipa: "JenkinsDemo.ipa")
end

這兩種方法,本質上是一樣的。上面只不過是lane之間的相互調用。

二、上傳一個TestFlight的測試包,

命令如下

desc "打beta包上傳TestFlight"
lane :beta do
match(type: "appstore", git_url: "git@172.16.11.154:repositories/test.git")
build_app(clean: true, output_name: "appstore", configuration: "Release", include_bitcode: true)
testflight(skip_submission: true)# 上傳testflight
end

上傳之前請做好前期的準備工作,在開發者賬號上創建APP,xcode上添加好appicon等。

首先:前期的匹配證書、導出ipa文件和打測試包差不多,改一下相應的參數就行了。只是增加了上傳到TestFlight,并且只是上傳一個ipa包并沒有將app相關的信息也上傳到TestFlight。

我在測試過程中遇到的問題:

1、因為是測試,所以一開始沒有添加相應尺寸的appicon,導致失敗。

2、在成功導出ipa包,準備上傳的時候報錯,如下圖 :


報錯

原因:上次上傳的動作被被記錄在UploadToken文件夾下面了,我們要進入user/.itmstransporter/UploadTokens該目錄下將里面的文件刪除,再次運行fastlane beta命令,就能上傳成功了,上傳過程會比較久,但終端會顯示上傳的進度,大概如下

DEBUG [2017-12-09 17:39:46.83]: [Transporter]: INFO:      File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 1880200/93265945, 2% completed
DEBUG [2017-12-09 17:40:07.92]: [Transporter]: INFO:      File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 3744600/93265945, 4% completed
DEBUG [2017-12-09 17:40:16.55]: [Transporter]: INFO:      File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 4676800/93265945, 5% completed
DEBUG [2017-12-09 17:40:24.74]: [Transporter]: INFO:      File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 5609000/93265945, 6% completed
DEBUG [2017-12-09 17:40:36.80]: [Transporter]: INFO:      File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 6541200/93265945, 7% completed
DEBUG [2017-12-09 17:40:55.42]: [Transporter]: INFO:      File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 8405600/93265945, 9% completed
DEBUG [2017-12-09 17:41:09.38]: [Transporter]: INFO:      File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 9337800/93265945, 10% completed
DEBUG [2017-12-09 17:41:20.30]: [Transporter]: INFO:      File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 10270000/93265945, 11% completed
DEBUG [2017-12-09 17:41:39.45]: [Transporter]: INFO:      File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 12134400/93265945, 13% completed
DEBUG [2017-12-09 17:41:49.63]: [Transporter]: INFO:      File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 13066600/93265945, 14% completed
DEBUG [2017-12-09 17:41:58.10]: [Transporter]: INFO:      File: 9a0450527b7b0dd213f32d8ad7a043d2.ipa 13998800/93265945, 15% completed

如果要直接上傳appstore,將上面的testflight命令換成pload_to_app_store命令就可以了。(因為這是制作demo,所以沒具體操作)。請自行嘗試!

結語

這篇博客只是提及了比較常用,也是比較實用的功能。起到拋磚引玉的作用fastlane還有很多強大的功能,這里沒有一一提及,有興趣的小伙伴可以多多研究

相關的知識:
atool
xcodebuild 自動化構建
蘋果下使用Gitosis的搭建git的服務器
fastlane文檔

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,443評論 6 532
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,530評論 3 416
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 176,407評論 0 375
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,981評論 1 312
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,759評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,204評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,263評論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,415評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,955評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,782評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,983評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,528評論 5 359
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,222評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,650評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,892評論 1 286
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,675評論 3 392
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,967評論 2 374

推薦閱讀更多精彩內容