美文网首页
fastlane+蒲公英脚本上传+自定义webhook

fastlane+蒲公英脚本上传+自定义webhook

作者: joeal | 来源:发表于2023-10-25 20:48 被阅读0次

前章

在之前的基础上改造。fastlane+蒲公英+Jenkins自动化打包配置流程

蒲公英上传脚本

下载 pgyer_upload.sh

该脚本作用为上传ipa文件,所以我们在该脚本后调用webhook接口,将消息转发到对应平台:飞书、企业微信、钉钉等

将下面webhook接口代码,copy到pgyer_upload.sh最后面

# 获取时间
time3=$(date "+%Y-%m-%d %H:%M:%S")
# 上传完成后会调用pgy平台的查询接口apiv2/app/buildInfo,会返回一个JSON对象
buildKey=$(echo $result | jq -r '.data | .buildKey')
echo ${buildKey}
downloadUrl="https://www.pgyer.com/${buildKey}"
echo ${downloadUrl}

curl --location 'https://open.larksuite.com/open-apis/bot/v2/hook/******************************' \
--header 'Content-Type: application/json' \
--data '{
    "msg_type": "post",
    "content": {
        "post": {
            "zh_cn": {
                "title": "应用更新提醒",
                "content": [
                    [
                        {
                            "tag": "text",
                            "text": "您的应用上传了新版本 "
                        }
                    ],
                    [
                        {
                            "tag": "text",
                            "text": "应用名称: xxx"
                        }
                    ],
                    [
                        {
                            "tag": "text",
                            "text": "应用类型: iOS"
                        }
                    ],
                    [
                        {
                            "tag": "text",
                            "text": "更新时间: '"$time3"'"
                        }
                    ],
                    [
                        {
                            "tag": "text",
                            "text": "更新内容: '"$buildUpdateDescription"'"
                        }
                    ],
                    [
                        {
                            "tag": "a",
                            "text": "请查看",
                            "href": "'"$downloadUrl"'"
                        }
                    ]
                ]
            }
        }
    }
}'

使用pgyer_upload.sh

在终端使用或在其它脚本中使用

./pgyer_upload.sh -k xxxxxxxxxxx -d '测试环境包' ~/Desktop/ipa/dev/xx.ipa

所以我们之前的Fastfile就可以如下修改:

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)

platform :ios do
    before_all do |lane|
        cocoapods
    end
 desc "以 development 方式打包并上传到蒲公英"
  lane :dev do

    puts "以 development 方式打包"
    gym(
      # 指定打包所使用的输出方式 (可选: app-store, package, ad-hoc, enterprise, development)
      export_method: "development",
      # 默认Release Debug
    configuration: "Debug",
      # 指定项目的 scheme 名称
      scheme: "xx",
      # 指定输出的文件夹地址
      output_directory: "~/Desktop/ipa/dev/",
    )

    puts "上传 ipa 包到蒲公英"
    #  这里就不使用插件上传包了 使用我们自定义上传脚本
    # pgyer( api_key: "xxxxxxxxxxxxxxxxx",update_description: "测试环境包")
    ./pgyer_upload.sh -k xxxxxxxxxxx -d '测试环境包' ~/Desktop/ipa/dev/xx.ipa
  end
end

比如在飞书群添加自定义机器人当上传成功后会自动发送消息:

截屏2023-10-26 20.42.40.png

相关文章

网友评论

      本文标题:fastlane+蒲公英脚本上传+自定义webhook

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