美文网首页
fastlane实现自动化打包上传测试平台

fastlane实现自动化打包上传测试平台

作者: 踩坑小分队 | 来源:发表于2017-05-18 17:08 被阅读249次

    <a href="https://github.com/fastlane/fastlane">fastlane</a>是什么?懒人的福利,实现各种自动化操作的工具。
    <a href="https://github.com/fastlane/fastlane">fastlane</a>可以干什么?
    Fastlane是用Ruby语言编写的一套自动化工具集和框架,每一个工具实际都对应一个Ruby脚本,用来执行某一个特定的任务,而Fastlane核心框架则允许使用者通过类似配置文件的形式,将不同的工具有机而灵活的结合在一起,从而形成一个个完整的自动化流程。

    首先看一下安装步骤:
    一步步走就好了
    Fastlane入门:安装篇

    接下来进行简单的使用,实现自动化打包并且发布到相关的测试平台
    Fastlane入门:初级使用篇

    整理的自动化打包的脚本
    关于这些工具的描述和使用可以看这里:https://docs.fastlane.tools/actions/Actions/

    #!/bin/bash
    
    #计时
    SECONDS=0
    
    #假设脚本放置在与项目相同的路径下
    project_path=$(pwd)
    #取当前时间字符串添加到文件结尾
    now=$(date +"%Y_%m_%d_%H_%M_%S")
    #打包完成之后,保存的地址,这里选择的是桌面
    finalPath="/Users/morris/Desktop/newBag"
    #希望得到的打包完成之后app的名称
    appName="你的app的名称,最好不要用中文"
    
    #指定项目的scheme名称
    scheme="当前项目对应的target的名称"
    #指定要打包的配置名
    configuration="Adhoc"
    #指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development, 和developer-id,即xcodebuild的method参数
    export_method='ad-hoc'
    
    #蒲公英的key
    PGY_User_Key="蒲公英的User_Key"
    PGY_API_Key="蒲公英的API_Key"
    #fir的token
    fir_token="fir 的 token"
    
    
    
    #指定项目地址
    workspace_path="$project_path/$scheme.xcworkspace"
    #指定输出路径
    output_path="$finalPath/$appName_${now}"
    #指定输出归档文件地址
    archive_path="$output_path/$appName_${now}.xcarchive"
    #指定输出ipa地址
    ipa_path="$output_path/$appName_${now}.ipa"
    #指定输出ipa名称
    ipa_name="$appName_${now}.ipa"
    #获取执行命令时的commit message
    commit_msg="$1"
    
    #输出设定的变量值
    echo "===workspace path: ${workspace_path}==="
    echo "===archive path: ${archive_path}==="
    echo "===ipa path: ${ipa_path}==="
    echo "===export method: ${export_method}==="
    echo "===commit msg: $1==="
    
    #先清空前一次build
    fastlane gym --workspace ${workspace_path} --scheme ${scheme} --clean --configuration ${configuration} --archive_path ${archive_path} --export_method ${export_method} --output_directory ${output_path} --output_name ${ipa_name}
    
    #上传到fir
    # echo "================= 上传到fir ================="
    # fir publish ${ipa_path} -T "${fir_token}" -c "${commit_msg}"
    
    
    echo "================= 上传到蒲公英 ================="
    curl -F "file=@${ipa_path}" -F "uKey=${PGY_User_Key}" -F "_api_key=${PGY_API_Key}" https://qiniu-storage.pgyer.com/apiv1/app/upload
    
    #输出总用时
    echo "===Finished. Total time: ${SECONDS}s==="
    

    你可以直接拷贝当前的脚本放在当前项目的目录下面。按照需求修改相关的参数。如果是普通的打包的话那就只需要修改这么几个参数就好了

    #打包完成之后,保存的地址,这里选择的是桌面
    finalPath="/Users/morris/Desktop/newBag"
    #希望得到的打包完成之后app的名称
    appName="你的app的名称,最好不要用中文"
    
    #指定项目的scheme名称
    scheme="当前项目对应的target的名称"
    
    #蒲公英的key
    PGY_User_Key="蒲公英的User_Key"
    PGY_API_Key="蒲公英的API_Key"
    #fir的token
    fir_token="fir 的 token"
    

    build_using_gym.sh 脚本的位置如图:

    image.png

    运行脚本之前别忘记了修改脚本的权限:chmod 777 脚本名

    参考资料
    Fastlane官网地址
    Fastlane github地址看这里
    推荐几篇介绍Fastlane的文章
    fastlane 教程: 入门
    使用fastlane实现iOS持续集成
    使用fastlane gym/xctool编写ipa打包脚本
    Fastlane自动化构建工具(完整解决测试和发布流程)

    相关文章

      网友评论

          本文标题:fastlane实现自动化打包上传测试平台

          本文链接:https://www.haomeiwen.com/subject/irwsxxtx.html