fastlane

1.初始化fastlane

fastlane init

2.在終端中,輸入以下命令,即可安裝蒲公英的 fastlane 插件。

fastlane add_plugin pgyer

3.修改fastlane文件夾里面的Fastlane

###將********對(duì)應(yīng)替換成自己項(xiàng)目對(duì)應(yīng)的
#測(cè)試包命令 (版本描述)
# fastlane develop desc:測(cè)試自動(dòng)發(fā)包3.6.0B1

# 網(wǎng)絡(luò)請(qǐng)求依賴
require 'net/http'
require 'uri'
require 'json'

#蒲公英api_key和user_key
pgyer_api_key  = "*****************"
pgyer_user_key = "*****************"

#下載地址
app_url = "*****************"
app_icon = "*****************"
#釘釘
DingTalkUrl = "*****************"



default_platform(:ios)

platform :ios do
  desc "Push a new release build to the App Store"
  lane :release do
    build_app(workspace: "*****************.xcworkspace", scheme: "*****************")
    upload_to_app_store
  end

  desc "測(cè)試包"
  lane :develop do |options|
    gym(
    #輸出的ipa名稱
    output_name:”*****************”,
    # 是否清空以前的編譯信息 true:是
    clean:true,
    # 指定打包方式,Release 或者 Debug
    configuration:"Debug",
    # 指定打包所使用的輸出方式,目前支持app-store, package, ad-hoc, enterprise, development
    export_method:"development",
    # 指定輸出文件夾
    output_directory:"./fastlane/development",
    )
     puts "開始上傳蒲公英"
     pgyer(api_key: “#{pgyer_api_key}”,
           user_key: “#{pgyer_user_key}”,
       password: "", install_type: "2",
       update_description: options[:desc]
    )

     puts '開始釘釘'
     app_patch = "./fastlane/development/*****************.ipa"
     app_version = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleShortVersionString")
     app_build_version = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleVersion")
     app_name    = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleDisplayName")
     dingTalk_url = DingTalkUrl
     markdown = 
        {
            msgtype: "link", 
                link: {
                text: {
                   各位小姐姐、小哥哥 最新版本已發(fā)布,辛苦測(cè)試", 
                title: "iOS #{app_name} #{app_version} (#{app_build_version}) 內(nèi)測(cè)版", 
                picUrl: "#{app_icon}", 
                messageUrl: "#{app_url}"
                }
        }
      uri = URI.parse(dingTalk_url)
      https = Net::HTTP.new(uri.host, uri.port)
      https.use_ssl = true

      request = Net::HTTP::Post.new(uri.request_uri)
      request.add_field('Content-Type', 'application/json')
      request.body = markdown.to_json

      response = https.request(request)
      puts "------------------------------"
      puts "Response #{response.code} #{response.message}: #{response.body}"

    
  end
    
end

ReactNative項(xiàng)目 自動(dòng)化打包

Jenkins

Fastlane

default_platform(:ios)

# 網(wǎng)絡(luò)請(qǐng)求依賴
require 'net/http'
require 'uri'
require 'json'

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

  workspace = "_RN.xcworkspace"
  scheme = "_RN"
  bundleid = "" 
  currentTime = Time.new.strftime("%Y-%m-%d %H-%M-%S")
  ipa_name = "AnItemForACar_RN"
  output_path = "../ios/fastlane/#{ipa_name} #{currentTime}"
  ipa_path = "#{output_path}/#{ipa_name}.ipa"
  build_number=""
# 蒲公英 api_key user_key
  pgyer_api_key = ""
  payer_user_key = ""


#釘釘
app_url=''
app_icon=''
dingTalk_url=''
# firim api_token
# firim_api_token = "xxxxxxxx"

# bugly app_id app_key
  bugly_app_id = ""
  bugly_app_key = ""

# crashlytics api_token build_secret
#  crashlytics_api_token = "xxxxxxx"
#  crashlytics_build_secret = "xxxxxxxx"

  before_all do |lane, options|
  
  #fastlane beta key1:value key2:value2
  #value  = options[:key1]
  #value2 = options[:key2]

  # 切到 develop 分支
  sh 'git checkout uat'
  # 代碼
  git_pull
  # build 號(hào)加1
  increment_build_number_in_plist(
    target: "#{scheme}"
  )
  #increment_version_number_in_plist(
  #    target: 'TestDemo',
  #    version_number: '1.0'
  #)
  # 下面是拿到新的版本號(hào),提交代碼
  build_number = get_build_number_from_plist(target: "#{scheme}")
  #git_commit(path:".", message:"Bump build to #{build_number}")
  #sh 'git push origin develop'
  
  # pod install
  cocoapods(repo_update: false)

  puts "build_number#{build_number}"

  end
  
  lane :test do |options|

  end
  lane :dev do |options|
    gym(
      scheme: "#{scheme}",
      export_method: "development",
      clean:true,
      workspace: "#{workspace}",
      output_directory: "#{output_path}",
      output_name: "#{ipa_name}",
      configuration: "Release",
    )
    puts "正在上傳蒲公英#{build_number}"
    
    pgyer(api_key: "#{pgyer_api_key}",
          user_key: "#{payer_user_key}",
          password:"",
          install_type:"2",
          update_description:"測(cè)試版本B #{build_number}"
          )
    puts "上傳蒲公英Success!?。。。?!"

    puts "正在發(fā)送釘釘通知"
     # 釘釘機(jī)器人
    #ipa_path = '/Users/dataenligten/.jenkins/workspace/AnItemForACar_RN_iOS/ios/fastlane/AnItemForACar_RN 2020-03-07 19-23-01/AnItemForACar_RN.ipa'
    app_version = get_ipa_info_plist_value(ipa: ipa_path, key: "CFBundleShortVersionString")
    app_build_version = get_ipa_info_plist_value(ipa: ipa_path, key: "CFBundleVersion")
    app_name = get_ipa_info_plist_value(ipa: ipa_path, key: "CFBundleDisplayName")
  markdown = {
    "msgtype": "link", 
    "link": {
        text: "iOS #{app_name} 更新了?。?!", 
        title: "iOS #{app_name} #{app_version} (B#{app_build_version}) 新版本", 
        picUrl: "#{app_icon}", 
        messageUrl: "#{app_url}"
    },
     "at": {
        isAtAll: true
    }

}

   
  uri = URI.parse(dingTalk_url)
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true
  request = Net::HTTP::Post.new(uri.request_uri)
  request.add_field('Content-Type', 'application/json')
  request.body = markdown.to_json
  response = https.request(request)
  puts "------------------------------"
  puts "Response #{response.code} #{response.message}: #{response.body}"
  puts "發(fā)送釘釘通知Success!!!!!!"


    #firim(firim_api_token: "#{firim_api_token}")

    # 上傳dSYM到Bugly
    #upload_app_to_bugly(
    #  file_path: "#{ipa_path}",
    #  app_key: "#{bugly_app_key}",
    #  app_id: "#{bugly_app_id}",
    #  pid: "2",  #應(yīng)用平臺(tái)標(biāo)識(shí), 用于區(qū)分產(chǎn)品平臺(tái) android:1 iOS:2
    #  download_limit: 999
    #)

    #上傳dSYM到crashlytics
    #crashlytics(
    #  api_token: "069c7f2852fe97ae2b9572f799200a2ae1da3621",
    #  build_secret: "0cb5ed2e8ff4ed31a5b03093e96fcbc3b81ade7021295e2a2e0afe35661c5d3b"
    #)
  end
    
  lane :adhoc do |options|
    build_ios_app(
      clean: true,
      workspace: "#{workspace}",
      output_directory: "#{output_path}",
      output_name: "#{ipa_name}",
      scheme: "#{scheme}",
      configuration: "Debug",
      export_method: "ad-hoc",
      export_options: {
        provisioningProfiles: {
          "#{bundleid}" => "Provisioning Profile Name",
        }
      },
      export_xcargs: "-allowProvisioningUpdates"
    )
    pgyer(api_key: "#{pgyer_api_key}", user_key: "#{payer_user_key}")

    firim(firim_api_token: "#{firim_api_token}")

    # 上傳dSYM到Bugly
    upload_app_to_bugl(
      file_path: "#{ipa_path}",
      app_key: "#{bugly_app_key}",
      app_id: "#{bugly_app_id}",
      pid: "2",  #應(yīng)用平臺(tái)標(biāo)識(shí), 用于區(qū)分產(chǎn)品平臺(tái) android:1 iOS:2
      download_limit: 999
    )

    #上傳dSYM到crashlytics 
    crashlytics(
      api_token: "#{crashlytics_api_token}",
      build_secret: "#{crashlytics_build_secret}"
    )
  end

  lane :app_store do |options|
    desc "Push a new release build to the App Store"
    increment_build_number(xcodeproj: "AnItemForACar_RN.xcodeproj")
    #build_app(workspace: "AnItemForACar_RN.xcworkspace", scheme: "AnItemForACar_RN")
    #upload_to_app_store

    build_ios_app(
      clean: true,
      workspace: "#{workspace}",
      output_directory: "#{output_path}",
      output_name: "#{ipa_name}",
      scheme: "#{scheme}",
      export_method: "app-store",
      export_options: {
        provisioningProfiles: {
          "#{bundleid}" => "Provisioning Profile Name",
        }
      },
      export_xcargs: "-allowProvisioningUpdates"
    )

    # 上傳dSYM到Bugly
    upload_app_to_bugl(
      file_path: "#{ipa_path}",
      app_key: "#{bugly_app_key}",
      app_id: "#{bugly_app_id}",
      pid: "2",  #應(yīng)用平臺(tái)標(biāo)識(shí), 用于區(qū)分產(chǎn)品平臺(tái) android:1 iOS:2
      download_limit: 999
    )

    #上傳dSYM到crashlytics
    crashlytics(
      api_token: "#{crashlytics_api_token}",
      build_secret: "#{crashlytics_build_secret}"
    )
    
    #可以上傳屏幕截圖、元數(shù)據(jù)、二進(jìn)制文件到App sotre Connect
    deliver(
      submit_for_review: true,
      automatic_release: false,
      force: true, 
      skip_metadata: true,
      skip_screenshots: true,
    )
  end
  end

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • fastlane運(yùn)行所需要的環(huán)境: OS X 10.9以上 Ruby 2.0 以上 Xcode 擁有一個(gè)開發(fā)者賬號(hào)...
    阿姣_0405閱讀 3,257評(píng)論 0 4
  • Fastlane是一套使用Ruby寫的自動(dòng)化工具集,旨在簡(jiǎn)化Android和iOS的部署過(guò)程,自動(dòng)化你的工作流。它...
    Cooci_和諧學(xué)習(xí)_不急不躁閱讀 1,562評(píng)論 2 10
  • Fastlane是一套使用Ruby寫的自動(dòng)化工具集,旨在簡(jiǎn)化Android和iOS的部署過(guò)程,自動(dòng)化你的工作流。它...
    mirrorzyb閱讀 71,058評(píng)論 27 355
  • Fastlane是一套使用Ruby寫的自動(dòng)化工具集,旨在簡(jiǎn)化Android和iOS的部署過(guò)程,自動(dòng)化你的工作流。它...
    流年易逝_(tái)李閱讀 475評(píng)論 0 1
  • 前言 每位iOS開發(fā)工程師都不可避免項(xiàng)目打包的時(shí)候,有時(shí)候繁瑣的打包即費(fèi)事又費(fèi)力,尤其是在大量測(cè)試下更是不可避免。...
    蔡吉閱讀 2,245評(píng)論 0 0

友情鏈接更多精彩內(nèi)容