阅读 301

fastlane iOS 自动化打包

1 cd 项目根目录

fastlane init
复制代码

2 选择自定义 3 配置文件

# 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

default_platform(:ios)


#targets = ['ElbC', 'ElbT', 'ElbF']
targets = ['ElbALL', 'ElbC', 'ElbC online', 'ElbF', 'ElbF online', 'ElbT', 'ElbT online']


ALL_DIR = Time.now.strftime("%Y-%m-%d %H:%M:%S")


platform :ios do
  

desc "ElbT 测试版本"
  lane :ElbT do 
    gym(scheme:"ElbT",
        export_method:"enterprise",
        output_directory:"~/Desktop/App/ElbT/",#文件路径
	output_name:"ElbT--#{ALL_DIR}.ipa"

         )
    end
lane :all do
targets.each do |t|
    gym(scheme:t,
        export_method:"enterprise",
        output_directory:"~/Desktop/App/All/#{ALL_DIR}/",#文件路径
	output_name:"#{t}--#{ALL_DIR}.ipa"
         )
end
end
end

复制代码

4 执行 终端切换至项目下的fastlane

目录预览
4.1 文件介绍 Appfile内部是个人开发者账号的配置 Fastfile 定义的是一个个的lane,执行不同的打包操作

操作实例 单个打包 ElbT fastlane ElbT

一键打包所有 fastlane all

5 打包过程

终端执行过程截图
打包成功
部分打包结果截图
6 结束
结果汇总

更新打包完成邮件自动发送

# 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

default_platform(:ios)


#targets = ['ElbC', 'ElbT', 'ElbF']
targets = ['ElbALL', 'ElbC', 'ElbC online', 'ElbF', 'ElbF online', 'ElbT', 'ElbT online']


ALL_DIR = Time.now.strftime("%Y-%m-%d-%H-%M-%S")


platform :ios do
  

desc "App打包功能"
  lane :App do
  #删除之前
      # exec "rm -rf rm -rf App"

puts "请按照顺序选择(从0开始):"
for index in 0 .. targets.length - 1 do
    item = targets[index]
    puts "#{index} #{item}\n"
end
$name = STDIN.gets
$name = $name.chomp
puts $name
$name = $name.to_i #转换为数字
while $name <0 || $name > targets.length do
	puts "请按照顺序选择(从0开始):#{targets}"
	$name = STDIN.gets
	$name = $name.chomp
	puts $name
	$name = $name.to_i
end

scheme = targets[$name] #选择的scheme
dest = "#{scheme}--#{ALL_DIR}.ipa"
current_dir = "./fastlane/"
local_dir = "App/ElbT/"
dest_dir = "#{current_dir}#{local_dir}"


#用户上传的文件
file_path = "'./#{local_dir}#{dest}'"
# puts file_path

    gym(scheme:scheme,
       export_method:"enterprise",
        output_directory: dest_dir,#文件路径
	output_name:dest)

puts "输入您的邮箱:\n"
$email_name = STDIN.gets
$email_name = $email_name.chomp

puts "您输入的邮箱是:#{$email_name}\n"

puts "输入您的邮箱密码:\n"
$email_password = STDIN.gets
$email_password = $email_password.chomp
puts "您输入的密码是:#{$email_password}\n"

$command = "python semail.py #{$email_name} #{$email_password} #{file_path}"
puts " 即将发送邮件 ~> #{$command}"
puts "发送请输入:1\n"
$commit = STDIN.gets
$commit = $commit.chomp
if $commit.to_i == 1 then
    #发送邮件
    exec "#{$command}"
    # 执行本地清理删除
        exec "rm -rf rm -rf App"


end
  end
end

复制代码

对应发送邮件Python脚本


![](https://user-gold-cdn.xitu.io/2019/1/29/168975b8f6fc132a?w=874&h=350&f=png&s=67647)

复制代码

文件配置结构:

文件目录外

打包之后确认

是否发送邮件

文件邮件发送

文件发送预览

查收结果

接受结果

关注下面的标签,发现更多相似文章
评论