美文网首页
[iOS] [jenkins] iOS打包脚本

[iOS] [jenkins] iOS打包脚本

作者: manajay | 来源:发表于2018-04-26 14:43 被阅读678次

    下面的是打包的脚本, 参数的配置 往下看⬇️

    #!/bin/bash -l
    export LANG=en_US.UTF-8
    cd ${ProjectName}/
    #更新 pod
    pod setup
    pod install --verbose --no-repo-update
    
    # info.plist路径
    project_infoplist_path="./${APP_NAME}/Info.plist"
    
    #取版本号
    bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${project_infoplist_path}")
    
    #取build值
    bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${project_infoplist_path}")
    
    DATE="$(date +%Y%m%d%H%M%s)"
    
    FLAG_NAME="${APP_NAME}_${APP_CONFIG}_${DATE}"
    
    IPA_PATH="${ARCHIVE_PATH}/${FLAG_NAME}/"
    
    ARCHIVE_PATH="${IPA_PATH}${FLAG_NAME}.xcarchive"
    
    
    echo "=================start================="
    echo "${IPA_PATH} - ${bundleShortVersion} - ${bundleVersion}"
    
    echo "=================clean================="
    xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${APP_SCHEME}"  -configuration "${APP_CONFIG}" clean
    
    echo "+++++++++++++++++build+++++++++++++++++"
    xcodebuild archive -workspace "${APP_NAME}.xcworkspace" -scheme "${APP_SCHEME}" -configuration "${APP_CONFIG}" -archivePath "${ARCHIVE_PATH}"
    
    echo "+++++++++++++++++export++++++++++++++++"
    xcodebuild -exportArchive -archivePath "${ARCHIVE_PATH}" -exportPath "${IPA_PATH}" -exportOptionsPlist "${EXPORT_OPTIONS_PATH}" --allowProvisioningUpdates
    
    #执行上传至蒲公英的命令
    if [ ${UPLOAD_IPA} = 1 ] ;then
        echo "++++++++++++++upload ipa +++++++++++++"
        curl -F "file=@${IPA_PATH}${APP_SCHEME}.ipa" -F "_api_key=${APIKEY}" https://www.pgyer.com/apiv2/app/upload
    fi
    
    
    • 设置的自动打包 注意 exportOptionsPlist

    • 上面的配置信息项可以用 jenkins的参数设置, 也可以自己写死

    参数.png
    • 当然也可以脚本自动生成 exportOptionsPlist
    
    echo "=================== create plist  @ `date`==================="
    cat <<EOF >export.plist
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>teamID</key>
    <string>${TEAM_ID}</string>
    <key>method</key>
    <string>${opt_method}</string>
    <key>signingStyle</key>
    <string>automatic</string>
    <key>stripSwiftSymbols</key>
    <true/>
    <key>thinning</key>
    <string>&lt;none&gt;</string>
    <key>compileBitcode</key>
        <true/>
    <key>uploadSymbols</key>
        <false/>
    </dict>
    </plist>
    EOF
    
    • 也可以 脚本传参, 使用长短命令 (说明 brew install gnu-getopt 安装传参的依赖, 主要是 mac 环境对于长短命令的使用区别与 linux)
    source /etc/profile
    #说明 brew install gnu-getopt 安装传参
    show_usage="args: [-m , -v , -b , -s , -w , -j]\
                                      [--method=, --app-version=, --build-version=, --sdk=, --workspace-path=, --job-build-version=]"
    
    #参数
    # 打包签名的方式 development/ad-hoc/app-store/enterprise
    opt_method="development"
    
    # 应用的版本号
    opt_app_version="1.3.1"
    
    # 应用的build构建版本号 主要用于TestFlight 区分同一个应用版本号下的多个测试包
    opt_build_version="1"
    
    # sdk: 真机/模拟器  iphoneos/iphonesimulator
    opt_sdk="iphoneos"
    
    # 工作目录路径
    opt_workspace_path=""
    
    # jenkins 当前job的构建号
    opt_job_build_version="1"
    
    echo "=================== 开始解析参数 ===================" # https://my.oschina.net/leejun2005/blog/202376
    GETOPT_ARGS=`/usr/local/Cellar/gnu-getopt/1.1.6/bin/getopt -o m:v:b:s:w:j: -al method:,app-version:,build-version:,sdk:,workspace-path:,job-build-version: -- "$@"`
    eval set -- "$GETOPT_ARGS"
    #获取参数
    while [ -n "$1" ]
    do
            case "$1" in
                    -m|--method) opt_method=$2; shift 2;;
                    -v|--app-version) opt_app_version=$2; shift 2;;
                    -b|--build-version) opt_build_version=$2; shift 2;;
                    -s|--sdk) opt_sdk=$2; shift 2;;
                    -w|--workspace-path) opt_workspace_path=$2; shift 2;;
                    -j|--job-build-version) opt_job_build_version=$2; shift 2;;
    
                    --) break ;;
                    *) echo $1,$2,$show_usage; break ;;
            esac
    done
    echo "=================== 解析参数结束 ==================="
    

    *额外的shell 命令

    覆盖info.plist版本号 CFBundleShortVersionString

    defaults write ${PLIST_PATH} CFBundleShortVersionString ${opt_app_version}
    

    额外补充, ExportOptions.plist


    image.png

    相关文章

      网友评论

          本文标题:[iOS] [jenkins] iOS打包脚本

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