Jenkins+Fastlane+蒲公英+钉钉

实现步骤:

1.fastlane安装与应用

2.jenkins本地配置与应用

一、fastlane安装与应用

1.安装fastlane环境:

sudo gem install fastlane --verbose  //安装fastlane

fastlane --version  //安装成功后查看版本

2.使用fastlane:

打开工程目录下的终端,初始化 fastlane 

fastlane init
 
新版本安装的时候出现了下面的分支选择,按要求选择就行
 
1. ?  Automate screenshots
2. ?‍✈️  Automate beta distribution to TestFlight (自动testfilght型配置)
3. ?  Automate App Store distribution (自动发布型配置)
4. ?  Manual setup - manually setup your project to automate your (需要手动配置内容)

选择4,手动配置内容

Appfile: 存储有关开发者账号相关信息
Fastfile: 核心文件,主要用于 命令行调用和处理具体的流程,lane相对于一个方法或者函数
Deliverfile: deliver工具的配置文件
metadata: 元数据文件夹
Matchfile: Match操作对应的配置文件

3.找到Fastfile 配置如下:“xxx”表示自己项目的一些参数数据配置,根据自己项目填写

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
# Xcode 9 默认不允许访问钥匙串的内容,必须要设置此项才可以,运行过程可能会提示是否允许访问钥匙串,需要输入电脑密码
# export_xcargs: "-allowProvisioningUpdates",


default_platform(:ios)

p_ipa_dir = "./build"
projectName = "xxx"

platform :ios do
    # 构建ipa包文件
    desc "上传到蒲公英测试包"
    lane :pgy_beta do
    # add actions here: https://docs.fastlane.tools/actions
    build_app(scheme: "#{projectName}",
        export_method: "development", #先用development证书,ad-hoc有点问题
        output_directory: p_ipa_dir,
        output_name: projectName,
        configuration: "Debug",
        clean: true,
        export_xcargs: "-allowProvisioningUpdates"
        )
    pgyer(api_key: "xxx",
        user_key:"xxx",
        update_description: "内测版")

    dingTalk_push
  end
  # 钉钉机器人
  desc "钉钉通知"
  lane :dingTalk_push do
    app_patch   = p_ipa_dir + "/#{projectName}"
    app_url = "xxx"
    app_icon = "xxx"
    dingTalk_url = "xxx"

    markdown =
    {
      msgtype: "link",
      link: {
          text: "🚀🚀🚀 测试包已上传到蒲公英 🚀🚀🚀",
          title: "iOS APP 内测版",
          picUrl: "#{app_icon}",
          messageUrl: "#{app_url}"
        }
      }

    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 = markdown.to_json

    response = https.request(request)
    puts "------------钉钉通知------------------"
    puts "Response #{response.code} #{response.message}: #{response.body}"
  end
end

 4.自动打包上传到蒲公英,打开工程目录下的终端,运行:fastlane pgy_beta  回车,上传完成后控制台会看到如下信息:

[20:35:51]: Cruising over to lane 'ios dingTalk_push' 🚖
[20:35:52]: ------------钉钉通知------------------
[20:35:52]: Response 200 OK: {"errcode":0,"errmsg":"ok"}
[20:35:52]: Cruising back to lane 'ios pgy_beta' 🚘

+------+----------------------------------+-------------+
|                   [32mfastlane summary[0m                    |
+------+----------------------------------+-------------+
| Step | Action                           | Time (in s) |
+------+----------------------------------+-------------+
| 1    | default_platform                 | 0           |
| 2    | build_app                        | 249         |
| 3    | pgyer                            | 95          |
| 4    | Switch to ios dingTalk_push lane | 0           |
+------+----------------------------------+-------------+

[20:35:52]: [32mfastlane.tools just saved you 6 minutes! 🎉[0m

此时蒲公英已上传,钉钉已发送推送:

二、jenkins本地配置与应用

1. 安装jenkins

brew install jenkins

2. 启动jenkins服务

$ brew services start jenkins
==> Successfully started `jenkins` (label: homebrew.mxcl.jenkins)

3.在浏览器中输入http://localhost:8080

cat ~/.jenkins/secrets/initialAdminPassword

输入password登陆。

4. 这样jenkins平台就搭建好了

5.安装插件:

选择Manager Plugins,管理插件,在可选插件页搜索并安装
1)DingTalk插件,这是为了来做构建后钉钉通知的
2)GitLab Plugin和Gitlab Hook Plugin,用GitLab管理源代码的
3)Xcode integration,用来使用Xcode命令打包工程的
4)Git parameter,用来进行参数化构建的

6.全局配置钉钉插件:

7.设置源码的仓库,以便让 Jenkins 知道我们的 iOS 项目的代码在哪里。目前我们的项目在 GitLab 仓库中(如果你用 Github 等其他仓库也是类似),

配置 SSH:点击Manage Credentials,在 Jenkins 的证书管理中添加 SSH。在 Jenkins 管理页面,选择“Credentials”,然后选择“Global credentials (unrestricted)”,点击“Add Credentials”,

如下图所示,填写自己的 SSH 信息,然后点击“Save”,这样就把 SSH 添加到 Jenkins 的全局域中去了。

8.在jenkins下新建一个项目,在项目下,点击配置,配置如下:

 

 9.点击保存后,点击build开始构建打包,每晚8点半开始自动打包,构建完成后会自动上传到蒲公英和钉钉通知:

 

到此就完成了!

下面是一些jenkins的命令:

启动:
后台服务模式:brew services start jenkins-lts
无需后台服务模式:jenkins-lts 或者直接jenkins

停止:
服务停止:brew services stop jenkins-lts
或者直接关闭终端

重新启动jenkins:brew services restart jenkins-lts

配置fir或者自动上传到AppStore也类似

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值