Jenkins + Fastlane

專案環境 cordova + angular4 hybrid app

挑戰: platform不上版控,將iOS和Android編譯成品出來,上次編譯iOS指令非常複雜,需要指定Provisioning Profiles和CODE_SIGN_IDENTITY,非常不人性化,這次使用fastlane工具來簡化android和iOS編譯。

Fastlane官方文件

安裝

1
gem install fastlane

在專案中初始化fastlane

1
2
cd 你的資料夾
fastlane init

設定完成後可以看到專案項目中會多一個 faselane 目錄。

  • Appfile

    放的是和App有關的資訊,包括 app identifier,apple id、team id…等等。
  • Fastfile

    這裡放的是具體要執行的命令
    指定了 team_id 是因為我的帳號有多個 team_id,需要指定一個。
    其中 lane 代表任務, beta 代表任務的名稱。
    在下方指令中,有 android 和 iOS 編譯指令。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    default_platform(:ios)

    platform :ios do
    desc "Description of what the lane does"
    lane :beta do

    automatic_code_signing(
    use_automatic_signing:true,
    team_id:"XXXXXXXXXX",
    path: "./cordova/platforms/ios/tcbb-mobile-bank.xcodeproj"
    )

    gym(
    workspace: "./cordova/platforms/ios/tcbb-mobile-bank.xcworkspace", #注意這邊的路徑喔!
    scheme: "tcbb-mobile-bank",
    export_method: "ad-hoc",
    export_options: "./ExportOptions_adhoc.plist",
    clean: true,
    destination: "generic/platform=iOS",
    output_directory: "./cordova/platforms/ios/ht_build",
    xcargs: "-UseModernBuildSystem=NO"
    )
    end
    end

    platform :android do
    desc "Description of what the lane does"
    lane :beta do
    gradle(
    project_dir: './cordova/platforms/android/',
    task: 'clean assembleDebug',
    )
    end
    end

執行指令帶入platform和lane的名稱 即可啟動fastlane的任務。

1
fastlane ios beta

結論

原本前篇需要xcodebuild指令弄一堆指令才能產出對應的ipa,透過fastlane可以簡化指令。而fastlane強大的地方還不止於此,還可以將編譯出來的成品自動上傳至appstore和testflight,一鍵完成繁雜的編譯和上傳ipa等等動作。