iOS自动化打包,完成之后发送钉钉消息

  • 确保 在Xcode上登录appleId,并且勾选了Automatically manage signing,也可以使用其他方式,请参考https://fastlane.tools
安装fastlane
$ brew cask install fastlane #也可以使用 sudo gem install fastlane -NV
$ cd `项目的根路径`
$ fastlane init
修改配置文件
#修改fastlane/Appfile文件
#[[APPLE_ID]]替换为你的apple_id,[[APP_IDENTIFIER]]替换为你的bundle_id

apple_id("[email protected]")             # Your Apple email address
app_identifier("com.tangkaifu.demo") # The bundle identifier of your app
$ touch Pluginfile # 在fastlane里面创建一个Pluginfile文本文件,Pluginfile和Appfile在同一个目录
$ vim Pluginfile  #编辑Pluginfile文件,也可以使用其他的文本编辑器打开

#把下面两行拷贝到Pluginfile文件当中
gem 'fastlane-plugin-firim'       #用于把ipa上传到fir上
gem 'fastlane-plugin-versioning'  #用于修改版本号
#创建一个.Gemfile文件
$ touch .Gemfile
#创建firim目录
mkdir firim
#修改Gemfile文件,追加

plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)
#修改Fastfile文件

require 'net/http'
require 'uri'
require 'json'

default_platform(:ios)

platform :ios do

  lane :build do

    enable_automatic_code_signing(path: "xxxxxx.xcodeproj")
    increment_build_number_in_plist(xcodeproj: "xxxxxx.xcodeproj",target:'xxxxxx')
    gym(workspace: "xxxxxx.xcworkspace",scheme: "xxxxxx",export_method: "development",output_directory: "firim/")

    version = get_version_number_from_plist(xcodeproj: "xxxxxx.xcodeproj",target: 'xxxxxx')
    buildVersion = get_build_number_from_plist(xcodeproj: "xxxxxx.xcodeproj", target: 'xxxxxx') 
    ipaFileName = "xxxxxx"+version+"\\("+buildVersion+"\\)"+".ipa"
                           
    firim(firim_api_token: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
    puts "\n\n============================\n xxxx"+version+" \(Build "+buildVersion+"\)测试版\nhttps://fir.im/ns9r\nhntx2018\n============================\n"

  # 钉钉机器人
   app_name = "xxxxxx" + version + "(" + buildVersion + ")"
   dingTalk_url = "钉钉机器人链接"
  
   markdown = 
    {
      msgtype: "link", 
      link: {
          text: "已经打包并上传到fir,密码:xxxxxx",
          title: app_name,
          picUrl: "xxxxxx",    #应用的icon
          messageUrl: "xxxxxx" #下载地址(fir)
      }
    }

   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 "Response #{response.code} #{response.message}: #{response.body}"
    end 
end
  • 以后如果需要打包就去到项目的根目录,执行fastlane build 即可

你可能感兴趣的:(iOS自动化打包,完成之后发送钉钉消息)