jenkins+fastlane 持续集成iOS项目(内附多个踩
1、下载好 JDK ,双击安装:



2、在 Jenkins 的官网 下载最新的 war 包。下载完成后,打开终端,进入到 war 包所在目录,执行以下命令:
java -jar jenkins.war --httpPort=8080
启动成功如图示:

待Jenkins启动后,在浏览器页面输入以下地址:
http://localhost:8080
展示如下:

按照提示步骤操作,设置相应的管理员账号和密码,一直到最终进入Jenkins配置页:

3、新建Item,输入项目名称,选择"Freestyle project",点击"确定":

4、项目生成成功,比如名称为:A ,如此,Jenkins下就会多一条名称为A的项目:

5、进入A项目,点击左边栏"配置"选项,根据需要配置相关信息,配置完成点击保存:

踩坑记录:
1、构建报错:
FATAL: null
java.lang.NullPointerException ...

解决方案:这个问题耗费了好长时间,最后发现是因为项目名称为中文,没有跟集成项目名保持一致,导致无法正常找到该项目路径报错。这里我的集成项目命名为:ABC,那么在第三步新建Item,输入的任务名称就必须也是ABC,与之对应。
2、归档失败,加载cocoapods集成的第三方文件失败:
Could not read serialized diagnostics file: Cannot Load File: Failed to open diagnostics file (in target 'Toast' from project 'Pods')
Could not read serialized diagnostics file: Cannot Load File: Failed to open diagnostics file (in target 'SDWebImage' from project 'Pods')�[0m
�[33m▸�[0m �[39;1mCompiling�[0m UIView+WebCache.m

解决方案:这种一般常见于集成了cocoapods管理第三方库项目,只需在jenkins的job项目命令行里加上:pod install即可
pod install
// fastlane打包脚本
bundle exec fastlane adhocLane

3、打包应用程序时出错:
** EXPORT FAILED **
[31mExit status: 70�[0m
error: exportArchive: Provisioning profile "A_AdHocProfile" doesn't include signing certificate "Apple Distribution: xxx公司. (xxx)".
Error packaging up the application�

解决方案:从错误日志来看,说的是导出失败,profile不包含Apple Distribution开头的签名证书,原因是苹果从Xcode11版本之后,要求额外再生成一份Apple Distribution签名的描述文件,

下载描述文件之后,双击安装,然后在jenkins的manage jenkins->Keychains and Provisioning Profiles Management里操作:

注意:
1、新版Mac系统下的登录钥匙串文件名为:login.keychain-db,直接上传至jenkins会报格式错误。
操作方法是将该文件拷贝至桌面,然后更改文件格式为:login.keychain,再次上传即可。
2、Keychain里Code Signing Identity的名称需要去系统钥匙串找到相应证书,打开"显示简介",拷贝出证书名称粘贴即可。
4、Could not find action, lane or variable 'pgyer'

解决方案:fastlane增加了打完包自动上传蒲公英脚本,但是未安装蒲公英插件,在项目根目录下执行命令行:fastlane add_plugin pgyer
即可解决。
5、Could not find fastlane-plugin-pgyer-0.2.2 in any of the sources

fastlane安装完蒲公英插件,直接用fastlane脚本跑是OK的,但在jenkins里跑,就会报源找不到fastlane-plugin-pgyer
解决方案:删除fastlane里安装的蒲公英插件,然后在jenkins里配置蒲公英插件及上传脚本
插件名:Upload to pgyer

名词解释:
1、pgyer uKey:注册蒲公英的User Key
2、pgyer api_key:注册蒲公英的API Key
3、scandir:jenkins里导出包的路径,要跟fastlane打包脚本的路径对应
4、file wildcard:包的文件名,一般是:xxx.ipa
6、Failed to connect to GitHub to update the CocoaPods/Specs specs repo

解决方案:这种一般是网络问题,导致pod update执行失败,更换网络或者翻墙反复尝试即可。
7、上传至蒲公英时未找到包文件
[UPLOAD TO PGYER] - scan dir:/./Packages
[UPLOAD TO PGYER] - scan dir isn't exist or it's not a directory!
[UPLOAD TO PGYER] - The uploaded file was not found,plase check scandir or wildcard!

解决方案:jenkins的job项目里,配置好上传至蒲公英包路径,这里我是直接写入jenkins里面的绝对包路径

8、如果需要其他设备通过域名形式访问打包机,设置如下:
1、终端找到路径/usr/local/Cellar/jenkins/2.240/homebrew.mxcl.jenkins.plist;
2、打开homebrew.mxcl.jenkins.plist,修改"--httpListenAddress=打包机IP",保存;
3、重启jenkins服务。