当前位置 博文首页 > dengren1956的博客:iOS 自动化打包发布(Fastlane+ Jenkins+蒲

    dengren1956的博客:iOS 自动化打包发布(Fastlane+ Jenkins+蒲

    作者:[db:作者] 时间:2021-09-20 16:27

      

      安装 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
    cs
    下一篇:没有了