iOS fastlane 自动化部署关联钉钉或者企业微信群消息提醒
本文 着重介绍 iOS使用 脚本 ,切换分支 ,获取最新代码 ,进行打包测试部署 ,关联钉钉或者企业微信 消息提醒 ,该文章 着重界面自己在使用过程中实现思路记载 ,如文中 有不合适的地方 欢迎指出 (已钉钉为例) fastlane 其他形式的打包 与此类似
1 fastlane 的安装
fastlane 的安装 [可以参考](www.jianshu.com/p/a3c586983…)
2 钉钉 机器人的添加
2.1 钉钉 机器人添加 ,钉钉群 ——>右键群设置——>群助手——>选择WebHook 自定义服务,编辑安全设置, 保存 此 Webhook 地址
2.2 钉钉机器人的 发消息有多种 形式 [具体可以参考](developers.dingtalk.com/document/ap…) 发消息可以根据需求 可采取不同的 形式 ,具体可参考钉钉开发文档 里面比较详细
3 fastlane 打包的相关 设置
3.1 关于 fastlane的相关打包 lane的设置。网上资料比较全,着重记录 里面添加 钉钉发消息的相关
3.2 fastlane lane 的设置
# 上传ipa到fir.im服务器,在fir.im获取firim_api_token answer = firim(firim_api_token: "******") url_answer = answer[sort] # 获取下载短连接 download_url = "http://d.firim.top/#{url_answer}" puts "下载链接: #{download_url} " dingTalk_url = "https://oapi.dingtalk.com/robot/send?access_token=*****" # 构造消息格式 actionCard = { "msgtype": "text", "text": { "content": "#{url_answer} 已更新,下载地址为:#{download_url} ,@****请知悉~" }, "at": { "atMobiles": [ "****" ], "isAtAll": false } } # { # "actionCard": { # "title": "iOS ", # "text": "哈 ", # "hideAvatar": "0", # "btnOrientation": "0", # "singleTitle": "下载地址", # "singleURL": "http://www.baidu.com" # }, # "msgtype": "actionCard" # } # puts "发送的钉钉消息:#{actionCard} " uri = URI.parse(dingTalk_url) https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri) request.add_field('Content-Type', 'application/json') request.body = actionCard.to_json response = https.request(request) # puts "------------------------------" puts "Response #{response.code} #{response.message}: #{response.body}"
以上为 发送钉钉消息主要部分
4 shell 自动拉取代码,切分分支 打包操作记录
判断是否是需要打包的分支 ,然后获取最新代码 ,开始打包,打包完成 发送钉钉消息提醒 ,清理打包缓存 执行 版本 传入 需要打包的分支名即可 ,在此脚本中 使用
# !/bin/bashecho "要开始 搞事情了"cd ~路径# bundle exec open .# 打包相关操作function makeIpaAction(){ echo "开始拉去最新代码" bundle exec git pull if [ $? -eq 0 ]; then echo "$1 分支 代码拉取成功" else echo "$1 分支 执行git pull 执行失败" exit; fi sleep 1 echo '开始打包' bundle exec fastlane fir if [ $? -eq 0 ]; then echo "6666" sleep 1 bundle exec git checkout . echo '清理缓存' # cd ~/Desktop/firim bundle exec open . # bundle exec find . -name ".zip" -print -exec rm -rf {} \; bundle exec sleep 2 bundle exec rm -f *.ipa* bundle exec rm -f *.zip* echo '打包工作已完成' else echo "客户端打包车失败" sleep 1 bundle exec git checkout . fi}# 检测是否 输入了名字if [ ! $1 ]then echo "####### 请输入分支名字 #######" exit;fi# 获取当前 分支 名字if currentBranch=$(git symbolic-ref --short -q HEAD)then echo 当前分支是 $currentBranchelse echo not on any branchfi# 判断当前分支与传入的分支是否一致if [ "$1" = "$currentBranch" ];then echo "[ = ]" makeIpaActionelse echo "[ =! ]" # 切换分支 git checkout $1 if [ $? -eq 0 ]; then
echo "分支切换成功 当前分支是: $1" makeIpaAction else echo "切换分支失败 请检测认真核对当前输入 分支名$1 是否正确" fifiecho 'finish'
或者 使用 curl 发送消息也可以curl 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxx' \
-H 'Content-Type: application/json' \
-d '{"msgtype": "text","text": {"content": "我就是我, 是不一样的烟火"}}'