使用fastlane自動(dòng)化部署APP

fastlane運(yùn)行所需要的環(huán)境:

  1. OS X 10.9以上
  2. Ruby 2.0 以上
  3. Xcode
  4. 擁有一個(gè)開發(fā)者賬號(hào)

因?yàn)閒astlane其實(shí)是一個(gè)Ruby腳本的集合,你必須安裝正確的Ruby版本∑沼撸可用一下命令確認(rèn)

安裝

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

xcode-select --install

如果已經(jīng)安裝玩徊,則會(huì)報(bào)一下錯(cuò)誤

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

如果沒安裝,終端會(huì)開始安裝CLT琼了。

3逻锐、通過(guò)rubygem安裝fastlane

sudo gem install fastlane -v 2.57.2 --verbose

初始化

打開終端,cd到你的工程目錄雕薪,然后執(zhí)行fastlane init
運(yùn)行結(jié)果如下

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

上述過(guò)程可能要輸密碼昧诱,將Apple ID的密碼正確輸入就可以了。

初始化完成之后所袁,工程目錄下就多了個(gè)fastlane文件夾盏档,內(nèi)容如下


sdf.png

這里肯定會(huì)被創(chuàng)建的是Appfile和Fastfile。如果Deliverfile燥爷,screenshots和metadata目錄沒被創(chuàng)建蜈亩,可以運(yùn)行deliver init來(lái)創(chuàng)建。

  • Appfile :用來(lái)存儲(chǔ)一些公共信息前翎,比如app_identifier稚配、apple_idteam_id港华、itc_team_id等道川。

  • Fastfile:用來(lái)定義所有的lane任務(wù)
    一開始的內(nèi)容如下:

# 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:
# 自動(dòng)更新fastlane
# update_fastlane

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

# 默認(rèn)使用平臺(tái)是ios愤惰,也就是說(shuō)可以定義多個(gè)平臺(tái)
default_platform :ios

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

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

  # 提交一個(gè)新的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

  # 部署一個(gè)新版本到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

  # 執(zhí)行l(wèi)ane之后的回調(diào)
  after_all do |lane|
    # This block is called, only if the executed lane was successful

    # slack(
    #   message: "Successfully deployed new App Update."
    # )
  end
  
  # 流程異常赘理,結(jié)束流程并輸出錯(cuò)誤信息
  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 這個(gè)大家庭中,主要但包括不盡于下列工具:

  • scan 自動(dòng)化測(cè)試工具扇单,很好的封裝了 Unit Test
  • sigh: 創(chuàng)建商模、更新、下載和修復(fù) provisioning profiles蜘澜。
  • match 同步團(tuán)隊(duì)每個(gè)人的證書和 Provision file 的超贊工具
  • cert: 自動(dòng)創(chuàng)建和維護(hù) iOS 代碼簽名證書施流。
  • gym: 創(chuàng)建和打包 iOS app。
  • deliver: 上傳屏幕截圖鄙信、元數(shù)據(jù)和 App 到 App 商店瞪醋。
  • produce: 創(chuàng)建可用于 iTunes Connect 和 Apple Developer Portal 的 iOS app。
  • snapshot: 自動(dòng)將 App屏幕截圖本地化到每種設(shè)備上装诡。
  • frameit: 將屏幕截圖適配到適當(dāng)?shù)脑O(shè)備屏幕大小银受。
  • PEM: 自動(dòng)創(chuàng)建和更新 Push 通知的 profile践盼。

fastlane 實(shí)戰(zhàn)

一、打一個(gè)測(cè)試包宾巍,并上傳到蒲公英交付測(cè)試.

1咕幻、創(chuàng)建一個(gè)匹配開發(fā)證書的lane

說(shuō)明:其中一個(gè)lane就是一個(gè)任務(wù),里面是一個(gè)個(gè)的action組成的工作流

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

創(chuàng)建一個(gè)lane:格式如下

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

說(shuō)明:主要用到了match工具肄程,其中type是指定環(huán)境,keychain_password选浑,服務(wù)器鑰匙串密碼蓝厌,match工具當(dāng)然不止這些參數(shù),想了解更多參數(shù)可以在終端執(zhí)行fastlane action match,或者fastlane match --help來(lái)查看文檔古徒。

創(chuàng)建好了拓提,在終端執(zhí)行如下:

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              | 這里顯示的是開發(fā)者賬號(hào) |
| 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          | 這里顯示的是開發(fā)者賬號(hào)                         |
| team_id           | 99WG99HF75                                     |
| keychain_path     | /Users/xyj/Library/Keychains/login.keychain-db |
| keychain_password | ********                                       |
| platform          | ios                                            |
+-------------------+------------------------------------------------+

[17:57:05]: Starting login with user '這里顯示的是開發(fā)者賬號(hào)'
[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                            | 這里顯示的是開發(fā)者賬號(hào)             |
| 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 '這里顯示的是開發(fā)者賬號(hào)'
[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 ??

這里主要說(shuō)一下幾點(diǎn):

1、git_url:git_url是git服務(wù)器地址,我沒指定git_url, 描函,匹配證書的時(shí)候崎苗,要求我輸入服務(wù)器地址。輸入完成后就會(huì)clone git服務(wù)器的代碼舀寓,

2胆数、驗(yàn)證證書:keychain_password就是為這步而存在的,這里由于我沒在git服務(wù)器下載證書互墓,所以沒找到必尼,但是fastlane為我重新創(chuàng)建了一個(gè)

3、描述文件:其實(shí)我已經(jīng)在證書(之前就創(chuàng)建的證書)上生成了描述文件篡撵,但是fastlane重新生成了證書判莉,所以他沒找到描述文件,又自動(dòng)給我重新生成了一個(gè)育谬。

上面三種情況是fastlane的正常流程券盅,但是我之前都創(chuàng)建好了,也就是說(shuō)他現(xiàn)在的操作不是我想看到的膛檀。接下來(lái)我們將匹配開發(fā)證書的lane改成下面這樣

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

并且登錄開發(fā)者賬號(hào)將新生成的證書和描述文件都刪掉锰镀,登錄git服務(wù)器,將證書下載并安裝好

再次在終端運(yùn)行,結(jié)果如下:

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              | 這里顯示的是開發(fā)者賬號(hào)                  |
| 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                            | 這里顯示的是開發(fā)者賬號(hào)             |
| 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 '這里顯示的是開發(fā)者賬號(hào)'
[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下你的代碼泳炉。工程下面多了兩個(gè)文件夾certsprofiles

  • certs文件夾下面包含一個(gè).cer文件和一個(gè).p12文件嚎杨。命名都是以證書id,這兩個(gè)文件分別用于自己開發(fā)和授權(quán)團(tuán)隊(duì)的小伙伴開發(fā)的花鹅。
  • profiles文件夾下面存放的是描述文件

當(dāng)你的倉(cāng)庫(kù)里面沒這兩個(gè),fastlane會(huì)為你重新創(chuàng)建證書和描述文件枫浙。如果有了刨肃。那就是上面這種情況古拴,fastlane會(huì)直接幫你匹配好證書和描述文件。

至此之景,創(chuàng)建一個(gè)匹配開發(fā)證書的lane就算完成了斤富。

2.創(chuàng)建一個(gè)打測(cè)試包的lane

創(chuàng)建一個(gè)lane,格式如下:

desc "打測(cè)試包"
  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三個(gè)參數(shù)锻狗,分別的含義為編譯之前是否clean满力、導(dǎo)出archive包的方式、編譯哪個(gè)configuration轻纪。

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

執(zhí)行上面的命令后刻帚,在工程目錄下可以看到導(dǎo)出的ipa包潦嘶。沒指定名字的話,ipa包的名字就是你的工程名崇众。

3.創(chuàng)建一個(gè)上傳到測(cè)試包到第三方分發(fā)平臺(tái)的lane掂僵,這里以蒲公英為例

上傳測(cè)試包到蒲公英、firim等第三方平臺(tái)顷歌,都要到相應(yīng)的第三方平臺(tái)注冊(cè)賬號(hào)锰蓬,這些平臺(tái)一般都會(huì)制作fastlane的插件來(lái)支持fastlane上傳測(cè)試包,這里做簡(jiǎn)單的介紹,查看詳細(xì)文檔請(qǐng)查看蒲公英官方文檔眯漩。

1芹扭、查看、安裝fastlane插件

在終端輸入 fastlane search_plugins可以查看當(dāng)前版本所有可用的插件赦抖,可以在里面看到pgyer插件,想知道如何使用請(qǐng)異步蒲公英官網(wǎng)查看舱卡。

安裝pgyer插件:

fastlane add_plugin pgyer

安裝完成后你就可以使用fastlane action pgyer來(lái)查看相關(guān)的參數(shù)以及使用了。

官網(wǎng)給出的例子是:

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

以上的 api_key 和 user_key队萤,請(qǐng)開發(fā)者在自己賬號(hào)(蒲公英)下的 應(yīng)用管理 - App概述 - API 中可以找到轮锥,并替換到以上相應(yīng)的位置。

上面要尔,我們已經(jīng)打好測(cè)試包了交胚,下面我們就上傳測(cè)試到蒲公英。

lane如下:

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

執(zhí)行結(jié)果如下:

?  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 ??

可以看到盈电,上傳成功后會(huì)給出一個(gè)鏈接,測(cè)試只需要打開這個(gè)鏈接就能掃碼安裝測(cè)試包了

小結(jié):

上面幾個(gè)步驟杯活,其實(shí)是可以在一個(gè)lane里面完成的匆帚。我改進(jìn)后的lane如下

desc "打測(cè)試包并上傳蒲公英"
lane :dev do
# 調(diào)用匹配開發(fā)證書的lane
matchDev
expIpa
uploadPGY
end

當(dāng)然,你可以這樣:

desc "打測(cè)試包并上傳蒲公英"
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

這兩種方法旁钧,本質(zhì)上是一樣的吸重。上面只不過(guò)是lane之間的相互調(diào)用互拾。

二、上傳一個(gè)TestFlight的測(cè)試包嚎幸,

命令如下

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

上傳之前請(qǐng)做好前期的準(zhǔn)備工作颜矿,在開發(fā)者賬號(hào)上創(chuàng)建APP,xcode上添加好appicon等嫉晶。

首先:前期的匹配證書骑疆、導(dǎo)出ipa文件和打測(cè)試包差不多,改一下相應(yīng)的參數(shù)就行了替废。只是增加了上傳到TestFlight箍铭,并且只是上傳一個(gè)ipa包并沒有將app相關(guān)的信息也上傳到TestFlight。

我在測(cè)試過(guò)程中遇到的問(wèn)題:

1椎镣、因?yàn)槭菧y(cè)試诈火,所以一開始沒有添加相應(yīng)尺寸的appicon,導(dǎo)致失敗状答。

2冷守、在成功導(dǎo)出ipa包,準(zhǔn)備上傳的時(shí)候報(bào)錯(cuò)惊科,如下圖 :


報(bào)錯(cuò)

原因:上次上傳的動(dòng)作被被記錄在UploadToken文件夾下面了拍摇,我們要進(jìn)入user/.itmstransporter/UploadTokens該目錄下將里面的文件刪除,再次運(yùn)行fastlane beta命令译断,就能上傳成功了授翻,上傳過(guò)程會(huì)比較久,但終端會(huì)顯示上傳的進(jìn)度,大概如下

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命令就可以了堪唐。(因?yàn)檫@是制作demo,所以沒具體操作)翎蹈。請(qǐng)自行嘗試淮菠!

結(jié)語(yǔ)

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

相關(guān)的知識(shí):
atool
xcodebuild 自動(dòng)化構(gòu)建
蘋果下使用Gitosis的搭建git的服務(wù)器
fastlane文檔

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末澄阳,一起剝皮案震驚了整個(gè)濱河市拥知,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌碎赢,老刑警劉巖低剔,帶你破解...
    沈念sama閱讀 206,214評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡襟齿,警方通過(guò)查閱死者的電腦和手機(jī)姻锁,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,307評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)猜欺,“玉大人位隶,你說(shuō)我怎么就攤上這事】螅” “怎么了涧黄?”我有些...
    開封第一講書人閱讀 152,543評(píng)論 0 341
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)副瀑。 經(jīng)常有香客問(wèn)我弓熏,道長(zhǎng),這世上最難降的妖魔是什么糠睡? 我笑而不...
    開封第一講書人閱讀 55,221評(píng)論 1 279
  • 正文 為了忘掉前任挽鞠,我火速辦了婚禮,結(jié)果婚禮上狈孔,老公的妹妹穿的比我還像新娘信认。我一直安慰自己,他們只是感情好均抽,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,224評(píng)論 5 371
  • 文/花漫 我一把揭開白布嫁赏。 她就那樣靜靜地躺著,像睡著了一般油挥。 火紅的嫁衣襯著肌膚如雪潦蝇。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,007評(píng)論 1 284
  • 那天深寥,我揣著相機(jī)與錄音攘乒,去河邊找鬼。 笑死惋鹅,一個(gè)胖子當(dāng)著我的面吹牛则酝,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播闰集,決...
    沈念sama閱讀 38,313評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼沽讹,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了武鲁?” 一聲冷哼從身側(cè)響起爽雄,我...
    開封第一講書人閱讀 36,956評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎沐鼠,沒想到半個(gè)月后盲链,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,441評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,925評(píng)論 2 323
  • 正文 我和宋清朗相戀三年刽沾,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片排拷。...
    茶點(diǎn)故事閱讀 38,018評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡侧漓,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出监氢,到底是詐尸還是另有隱情布蔗,我是刑警寧澤,帶...
    沈念sama閱讀 33,685評(píng)論 4 322
  • 正文 年R本政府宣布浪腐,位于F島的核電站纵揍,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏议街。R本人自食惡果不足惜泽谨,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,234評(píng)論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望特漩。 院中可真熱鬧吧雹,春花似錦、人聲如沸涂身。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,240評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)蛤售。三九已至丁鹉,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間悴能,已是汗流浹背揣钦。 一陣腳步聲響...
    開封第一講書人閱讀 31,464評(píng)論 1 261
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留搜骡,地道東北人拂盯。 一個(gè)月前我還...
    沈念sama閱讀 45,467評(píng)論 2 352
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像记靡,于是被迫代替她去往敵國(guó)和親谈竿。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,762評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容