zoukankan      html  css  js  c++  java
  • Jenkins+Git+Fastlane+Fir CI集成

    上一篇有讲关于fastlane自动化部署,本篇将会着重讲关于fastlane的实际应用。

    目标:

    • 利用自动化jenkins打包工具,自动拉取git仓库代码
    • 不需要通过手动检查修改xcode中项目配置修改(provisioning,codesigning)
    • 支持多渠道(chanel,appstore,enterprise,develop,adhoc)
    • 支持一键上传appstore(首次需要输入账户,密码)
    • 企业版本自动上传序号dsym文件到对应平台(fir的hdbug平台)

    创建fastlane文件

    进入项目目录在终端输入fastlane init命令,会要求输入Apple ID信息按照提示输入即可,选择是否deliver等初始化工作按照上篇讲解即可。操作完成即可看到下图所示的基本内容,下面会对图中文件一一讲解:

    General preferences pane

    fastlane源码解析

    一. 统一管理fastlane操作脚本文件

    1.外界控制版本号,并且控制渠道AdHoc AppStore Develop InHouse

    1
    2
    3
    4
    versionNumber=$2 # 1.0.0
    outLaneName=$1 #"AdHoc AppStore Develop InHouse"其中的一种,外界传入
    curDir=`pwd`
    distDir="$curDir/build"

    2.根据外界传递的数据控制,调用fastlane的lane操作

    1
    2
    3
    4
    5
    6
    7
    8
    9
    basicLanes="AdHoc Release Develop InHouse"
    for laneName in $basicLanes
    do
    if [ $outLaneName == $laneName ]
    then
    echo "outer setValue is:$outLaneName"
    fastlane $laneName version:$versionNumber
    fi
    done

    二. Appfile文件修改

    1.同一个app,appfile控制渠道(appstore非appstore的)。当然也可以通过控制多个app区分不同的lane即可

    1
    2
    3
    4
    5
    6
    app_identifier "com.tww.test" # App Store的版本的app_idendifier
    apple_id "2501046883@qq.com" # 对应的账号appid
    for_lane :InHouse do #企业及账号的
    app_identifier "com.tww.test.enterprise" # 企业及账号app_idendifier
    apple_id "2501046883@qq.com"" # 对应的账号的密码
    end

    三. Deliverfile文件修改

    1.上传appstore的deliver文件

    1
    2
    app_identifier "com.tww.test" # The bundle identifier of your app
    username "2501046883@qq.com" # your Apple ID user

    四. Fastfile文件修改

    1.修改app identifier(就是bundle id,例如:com.husor.beibei)注意xcode7.0以上苹果改了CFBundleIdentifier or PRODUCT_BUNDLE_IDENTIFIER

    1
    2
    3
    4
    5
    update_app_identifier(
    xcodeproj:PROJECT_FILE_PATH ,#project路径
    plist_path:"#{PLIST_FILE_PATH}" ,#plist文件的路径
    app_identifier:app_id
    )

    2.修改team(teamid)

    1
    2
    3
    4
    5
    6
    7
    def prepare_update_project_team(team_id)

    update_project_team(
    path:PROJECT_FILE_PATH,
    teamid: "K4W62VQT27"
    )
    end

    3.修改info_plist(就是bundle id,例如:com.tww.test)

    1
    2
    3
    4
    5
    6
    7
    8
    def prepare_update_info_plist(app_id)
    update_info_plist(
    xcodeproj:PROJECT_FILE_PATH ,
    plist_path:"#{PLIST_FILE_PATH}" ,
    app_identifier:app_id

    )
    end

    4.修改版本号和build号(修改为外部传入的版本,例如:1.0.0和100)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    def prepare_version(options)
    #say 'version number:'
    #say options[:version]
    increment_version_number(
    version_number: options[:version],
    大专栏  Jenkins+Git+Fastlane+Fir CI集成an class="line"> xcodeproj: PROJECT_FILE_PATH,
    )

    #say 'build number:'
    #say options[:build]
    increment_build_number(
    build_number: options[:version],
    xcodeproj: PROJECT_FILE_PATH,
    )
    end

    5.修改签名的配置,配置对应的provision file,事先将个provisioning放入provision文件内容,关于怎么找到对应的provison可以通过xcode配置正确后,查看project文件(/Users/tianww/Library/MobileDevice/Provisioning Profiles/)找到后复制到这里。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    def prepare_version(options)
    #say 'version number:'
    #say options[:version]
    increment_version_number(
    version_number: options[:version],
    xcodeproj: PROJECT_FILE_PATH,
    )

    #say 'build number:'
    #say options[:build]
    increment_build_number(
    build_number: options[:version],
    xcodeproj: PROJECT_FILE_PATH,
    )
    end

    6.编译打包为ipa使用gym,当然首先要安装gym。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    def generate_ipa(typePrefix,options,exportMethod,codeSignID)
    #say 'generate ipa'
    fullVersion = options[:version]
    gym(
    workspace: './BeiBeiAPP.xcworkspace',
    configuration: "#{typePrefix}",
    scheme: "#{SCHEME_NAME}",
    output_directory: "./build",
    output_name: "#{APP_NAME}.ipa",
    archive_path: './build/',
    clean: true,
    codesigning_identity: "#{codeSignID}",
    provisioning_profile_path: "./fastlane/provision/#{typePrefix}.mobileprovision",
    include_symbols: 'true',
    include_bitcode: 'false',
    export_method: "#{exportMethod}"
    )
    end

    或者使用shenzhen ,但是发现使用shenzhen比gym的要大

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    def generate_ipa(typePrefix,options,exportMethod,codeSignID)
    #say 'generate ipa'
    fullVersion = options[:version] + '.' + options[:build]
    channelId = options[:channel_id]
    ipa(
    configuration: typePrefix,
    scheme:"#{SCHEME_NAME}",
    clean: true,
    destination:"./build",
    ipa:"#{APP_NAME}_#{fullVersion}_#{typePrefix}.ipa",
    archive:false
    )

    end

    7.构建不同的lane,处理不同的包。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    # 企业版 证书打包
    desc "InHouse by personal apple account"
    lane :InHouse do |options|
    typePrefix = 'InHouse'
    exportMethod = 'enterprise'
    codeSigningIdentify = 'iPhone Distribution:tww'
    prepare_version(options)
    update_provision(typePrefix)
    prepare_update_project_team('K4W62VQT27')
    prepare_update_app_identifier("#{INHOUSE_IDENTIFIER}")
    prepare_update_info_plist("#{INHOUSE_IDENTIFIER}")
    generate_ipa(typePrefix,options,exportMethod,codeSigningIdentify)
    end

    参考

    • fastlane actions所有的actions的详细讲解。当然我们也可以在terminate中输入以下命令:

      1
      2
      fastlane actions(会列出所有的action)
      fastlane action deliver(单独详细的列出deliver的action对应的所有的内容)
  • 相关阅读:
    Angular与PHP之间的不同的请求方式(post/get)导致的传参问题
    项目当中会使用到的---获取主机名
    JavaScript eval() 函数
    PHP 数组排序
    PHP Switch 语句
    PHP strlen()函数和strpos()函数
    Array.prototype.map()和Array.prototypefilter()
    25.参考链接
    24.ArrayBuffer
    23.读懂 ECMAScript 规格
  • 原文地址:https://www.cnblogs.com/lijianming180/p/12258918.html
Copyright © 2011-2022 走看看