iOS 自動化打包發布(Fastlane+ Jenkins+蒲公英)


  

  安裝 Xcode 命令行工具:xcode-select --install

  安裝 fastlane:sudo gem install fastlane --verbose

  安裝成功后查看版本:fastlane --version

  配置 fastlane:

  終端進入工程主目錄:

  輸入:fastlane init

  

  出現:What would you like to use fastlane for? 選項時,選擇 3,輸入蘋果開發者賬號和密碼。

  下面的步驟根據提示輸入回車,完成后,fastlane 文件中會多出兩個配置文件 Appfile 和 Fastfile

  

  Appfile 中:

  # app_identifier("[[APP_IDENTIFIER]]") # The bundle identifier of your app
  # apple_id("[[APPLE_ID]]") # Your Apple email address

  # For more information about the Appfile, see:
  # https://docs.fastlane.tools/advanced/#appfile

  替換對應的 bundle identifier 和 開發者賬號。

  Fastfle 配置:

# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

# 定義fastlane版本號
fastlane_version “2.116.1” 

# 定義打包平台
default_platform(:ios)

def updateProjectBuildNumber

currentTime = Time.new.strftime("%Y%m%d")
build = get_build_number()
if build.include?"#{currentTime}."
    # => 為當天版本 計算迭代版本號
    lastStr = build[build.length-2..build.length-1]
    lastNum = lastStr.to_i
    lastNum = lastNum + 1
    lastStr = lastNum.to_s
if lastNum < 10
    lastStr = lastStr.insert(0,"0")
    end
    build = "#{currentTime}.#{lastStr}"
else
# => 非當天版本 build 號重置
    build = "#{currentTime}.01"
    end
    puts("*************| 更新build #{build} |*************")

# => 更改項目 build 號
increment_build_number(
build_number: "#{build}"
)
end

#指定項目的scheme名稱
scheme=“修改成你的工程scheme名稱”

#蒲公英api_key和user_key
api_key=“修改成蒲公英管理后台中應用的 API Key”
user_key=“修改成蒲公英管理平台中應用的 User Key”


platform :ios do
  lane :development_build do|options|
branch = options[:branch]

puts “開始打development ipa”

updateProjectBuildNumber #更改項目build號

# 開始打包
gym(
#輸出的ipa名稱
output_name:”#{scheme}_#{get_build_number()}”,

# 是否清空以前的編譯信息 true:是
clean:true,

# 指定打包方式,Release 或者 Debug
configuration:"Debug",

# 指定打包所使用的輸出方式,目前支持app-store, package, ad-hoc, enterprise, development
export_method:"development",

# 指定輸出文件夾
output_directory:"./fastlane/build",
)

puts "開始上傳蒲公英"
# 開始上傳蒲公英
pgyer(api_key: “#{api_key}”, user_key: “#{user_key}”)
  end
end

  

安裝蒲公英插件:fastlane add_plugin pgyer  (⚠️進入到工程目錄中執行安裝蒲公英插件命令)

  

  選擇 y

  

  輸入電腦密碼,安裝成功,出現:Successfully installed plugins。

 

  開始打包:fastlane development_build

  

  進入蒲公英后台就可以查看到最新版本更新了。

  

  遇到的坑:

  1、Could not find action, lane or variable 'pgyer'. Check out the documentation for more details: https://docs.fastlane.tools/actions

  找不到蒲公英插件,原來是安裝目錄錯了,應該在工程目錄下安裝:fastlane add_plugin pgyer 

  2、xcodebuild -showBuildSettings timed out after 4 retries with a base timeout of 3. You can override the base timeout value with the environment variable FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT, and the number of retries with the environment variable FASTLANE_XCODEBUILD_SETTINGS_RETRIES 

  重試打包命令或修改編譯時長。

  3、[!] Exit status of command 'cd /*** && agvtool what-version -terse' was 6 instead of 0. (FastlaneCore::Interface::FastlaneShellError)

  Fastfile 中配置的 Build 自增,需要在 Xcode ->build setting -> version -> current 中配置如下:

  

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM