Jenkins 打包最后一步是通知到钉钉或者企微群,会附带changlog。下列脚本只是作为调用 fastlane 的入口,fastlane 核心方法是 build_app以及 fir 或者 pgy plugin 的调用。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #!/bin/bash -l export LANG=en_US.UTF-8 export LANGUAGE=en_US.UTF-8 export LC_ALL=en_US.UTF-8
# ====================== 自定义字段 ========================= # 标识 name="xxx_iOS" # 仓库分支名称 branch=${GIT_BRANCH} # 构建类型 1=Debug测试包, 2=Release测试包 archiveType=2 echo -e ${ARCHIVE_TYPE} # 工程路径 PROJECT_PATH=${WORKSPACE} echo -e ${PROJECT_PATH}
# Change Log echo -e "******************** 更新日志 ********************" LASTBUILDCOMMIT=${GIT_PREVIOUS_SUCCESSFUL_COMMIT} if [ -n "$LASTBUILDCOMMIT" ]; then echo "LASTBUILDCOMMIT = $LASTBUILDCOMMIT" LOGTIME=$(git log --pretty=format:'%ct' $LASTBUILDCOMMIT '-1') else LOGTIME=$((` date -v-3d '+%s'`)) echo "用3天前的时间戳"$LOGTIME fi GIT_CHANGE_LOG=$(git log --no-merges --pretty=format:'%s' --after $LOGTIME '-20' | grep -E '^fix|^feat|^opt') echo "=======" echo "$GIT_CHANGE_LOG" echo "=======" UPDATEINFO_PATH_TMP=${PROJECT_PATH}/git_log.txt echo "$GIT_CHANGE_LOG" > $UPDATEINFO_PATH_TMP
# 开启代理,安装构建所需运行环境,bundle pod更新 export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
echo -e "******************** 指定 gem 以及 plugin ********************" bundle update
echo -e "******************** 安装CocoaPods依赖库 ********************" pod update
# 通知到企业微信机器人 # App迭代机器人🤖 WECHAT_BOT="xxxx"
# At的人 WECHAT_PERSON="xxxx"
# 开始构建 if [ "$archiveType" = "1" ]; then echo -e "******************** 开始构建Debug ********************" bundle exec fastlane alpha_debug WECHAT_BOT:${WECHAT_BOT} AT_PERSON:${WECHAT_PERSON} BRANCH:${name}_${branch} GITLOG:1 else echo -e "******************** 开始构建Release ********************" bundle exec fastlane alpha_release WECHAT_BOT:${WECHAT_BOT} AT_PERSON:${WECHAT_PERSON} BRANCH:${name}_${branch} GITLOG:1 fi
|
lane代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| desc "上传Debug安装包至fir.im" lane :alpha_debug do |options| set_build_number build_number = get_build_number(xcodeproj: "xxx.xcodeproj") version_number = get_version_number(xcodeproj: "xxx.xcodeproj", target: "xxx") build_app(workspace: "xxx.xcworkspace", configuration: "Debug", scheme: "xxx", clean: true, include_bitcode: false, export_xcargs: "-allowProvisioningUpdates", export_options: "./fastlane/ExportOptionsDev.plist", build_path: "./fastlane/Archives", archive_path: "./fastlane/Archives/xxx.xcarchive", output_directory: "~/Desktop/xxx-IPA/AlphaDebug", output_name: "xxx_v#{version_number}(#{build_number})")
answer = fir_cli api_token: "xxx", need_release_id: true download_url = "http://d.maps9.com/#{answer[:short]}?release_id=#{answer[:release_id]}" sh(command: "chmod +x weRobot.sh", log: false) weGroup = options[:WECHAT_BOT] wePerson = options[:AT_PERSON] branch = options[:BRANCH] gitLog = options[:GITLOG] if weGroup build_des = "xxx:iOS测试包[Debug_#{branch}_#{version_number}_#{build_number}]" sh(command: "chmod +x weRobot.sh", log: false) sh(command: "./weRobot.sh #{build_des} #{download_url} #{weGroup} #{wePerson} #{gitLog}", log: true) else build_des = "xxx:iOS测试包[Debug_#{branch}_#{version_number}_#{build_number}]" sh(command: "chmod +x old_weRobot.sh", log: false) sh(command: "./old_weRobot.sh #{build_des} #{download_url}", log: true) end end
|
不用第三方包下载平台(fir 或者 pgy)的话, xcodebuild 的时候可以指定 mainfest 格式,自动化上传自己的 https 服务器平台。