作者:北斗七星 | 来源:互联网 | 2023-09-02 13:10
ContinuousIntegration持续集成(简称CI):一个可以自动构建的过程,自动编译代码,可以自动分发,部署和测试。一、安装我们来开始安装Jenkins。从官网http
Continuous Integration 持续集成(简称CI):一个可以自动构建的过程,自动编译代码,可以自动分发,部署和测试。
一、安装
我们来开始安装Jenkins。从官网https://jenkins.io/ 上下载最新的pkg安装包。
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/d942b7ec373849c3.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/189d8/978/7dbdf0f38ad53545.jpeg)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/e88efe5b0a13a7fa.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/8ad8f3bf8da691df.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/d67981797265d9c7.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/443b30bb45e66690.webp)
也可以下载jenkins.war, 然后运行Java -jar jenkins.war,进行安装。
安装完成之后,Safari可能会自动打开,如果没有自动打开,打开浏览器,输入http://localhost:8080
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/bcafc120671304eb.webp)
这个时候可能会报一个错误。如果出现了这面的问题。出现这个问题的原因就是Java环境有问题,重新Java环境即可。
这个时候如果你重启电脑会发现Jenkins给你新增了一个用户,名字就叫Jenkins,不过这个时候你不知道密码。你可能会去试密码,肯定是是不对的,因为初始密码很复杂。这个时候正确做法是打开http://localhost:8080会出现下图的重设初始密码的界面。
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/189d8/978/7dbdf0f38ad53545.jpeg)
按照提示,找到/Users/Shared/Jenkins/Home/ 这个目录下,这个目录虽然是共享目录,但是有权限的,非Jenkins用户/secrets/目录是没有读写权限的。
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/45a090220e38e09d.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/7cccb7e4b6cb5cb8.webp)
打开initialAdminPassword文件,复制出密码,就可以填到网页上去重置密码了。如下图
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/72fd2c126203a875.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/70be2ca197098d98.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/1e3db12dd78db092.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/189d8/978/7dbdf0f38ad53545.jpeg)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1e618/c5a/d5d40da532c3a782.png)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/b386c433a16f5497.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/189d8/978/7dbdf0f38ad53545.jpeg)
一路安装过来,输入用户名,密码,邮件这些,就算安装完成了。
还是继续登录localhost:8080 ,选择“系统管理”——“管理插件”,我们要先安装一些辅助插件。
二、安装插件
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/857a46d091981bac.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/b428d8f746fb8d47.webp)
安装完了这个,我们就可以配置一个构建项目了。
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/70be2ca197098d98.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1e618/bdf/129913486c37ddf6.jpeg)
点击新建好的项目,进来配置一下General参数。
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/189d8/978/7dbdf0f38ad53545.jpeg)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/7d7ef3f69d479716.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/ea91d84a82557da5.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/3e641eb5f5c8cd90.webp)
点击“增加构建步骤->点击“Xcode””,会新增以下界面
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/780a3060eeed6a4e.webp)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/8373b1277127c518.webp)
Target是构建的目标。如果留空,那么就会构建所有的目标。
Clean before build这个选项建议勾选,构建之前最好Clean一下,至于为什么,我也不知道,我们开发之前打包的时候没有Clean,有时候会出一些莫名其妙的bug。
Configuration此处填写Release或者Debug,指的是IOS打包的类型,Debug版本还是Release版本。
Pack application and build .ipa需要打钩,因为我们需要打包成ipa文件来安装。
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/bdd1ca32a69bc8b2.webp)
Export method 打包的环境
ipa filename pattern打包成ipa文件的名称,就是最终的xxx.ipa。
Output directory 打包生成的IPA文件所在的位置
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/18ace/696/1d8e759bd3e6bbec.jpeg)
Xcode Workspace File是项目的地址,xxx.xcworkspace的地址。前面的地址是固定的/Users/Shared/Jenkins/Home/workspace/,后面根据具体项目修改
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/433ea70d6ea577b1.jpeg)
Build output directory是构建后的输出地址,我这里设置于ipa文件地址一致。直接写这个就可以
注意:如果你的项目是使用.project。请使用Xcode Project File,留空Xcode Workspace File.
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/189d8/978/7dbdf0f38ad53545.jpeg)
Keychain path是固定填写${HOME}/Library/Keychains/login.keychain
Keychain password指的是你的授权密码,不是证书密码。
注意:${HOME}目录指的是Jenkins的根目录,也就是/Users/Shared/Jenkins,如果你的jenkins是新装的,你会发现Library目录中压根就没有Keychains目录。你需要去/Users/管理员用户名/Library目录下把Keychains目录复制过来。
如果提示Profile的错误:
我第一次导入证书和Provisioning Profiles文件,就遇到了一点小“坑”,我当时以为是需要证书,但是这里需要的Keychain,并不是cer证书文件。这个Keychain其实在/Users/管理员用户名/Library/keychains/login.keychain,当把这个Keychain设置好了之后,Jenkins会把这个Keychain拷贝到/Users/Shared/Jenkins/Library/keychains这里,(Library是隐藏文件)。Provisioning Profiles文件也直接拷贝到/Users/Shared/Jenkins/Library/MobileDevice文件目录下。
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/ddcc574beb16294e.jpeg)
如果要上传蒲公英,在shell里添加下面这句话
curl -F “file=@ipa所在路径” -F “uKey=用户User Key” -F “_api_key=用户API Key” https://qiniu-storage.pgyer.com/apiv1/app/upload
uKey、_api_key为蒲公英的账号信息
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/2d903861d5ad779c.png)
至此所有的信息配置完毕。
点击“立即构建”就可以上传到蒲公英上。
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/70be2ca197098d98.webp)
需要注意的地方:
1.证书问题:
在执行过程中需要将自己的开发证书先拷贝到系统证书中。这是因为钥匙串中的证书拥有者是管理者,不是jenkins用户,jenkins用户是没有权限操作证书的
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/02c379d60086f382.webp)
2.pod: command not found
如果是用的cocoapods管理的话,需要添加环境变量,否则会提示pod: command not found
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/2fdc212433a29829.png)
环境变量添加的方法
在终端输入 echo $PATH
将PATH值全部复制,然后贴到 系统管理 — 系统设置 –Environment variables — 键:PATH 值:刚才PATH的值
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/7cccb7e4b6cb5cb8.webp)
3.GitLab ssh认证
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/ed19db63ee478b98.png)
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/1113165c4904ecc5.webp)
Private Key的生成可以参照GitLab的文档
在终端执行 cat ~/.ssh/id_rsa 就可以生成Private Key
cat ~/.ssh/id_rsa.pub 生成的是公钥
4.WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/5b97d3b808d031e2.webp)
则需要在执行shell的时候添加export LANG=en_US.UTF-8这句话。
5.Setting up CocoaPods master repo
Jenkins运行提示到这句话的时候,一直在转圈圈,放心好了,最起码到现在你的配置还是正确的,因为Jenkins在下载cocoapods的环境,大概1G多的东西,需要的时间可能有点长。
成功之后就是下面的提示
![《Jenkins持续集成踩过的坑》](https://img.php1.cn/3cd4a/1eebe/cd5/e3aa5425383ba10d.png)
6.ProcessPCH xxx/PrefixHeader.pch normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
这个问题好纠结,百度了好久也没发现是什么问题,最后问了同事说是引第三方头文件的问题,我之前写的时候#import “xxx.h”,改成#import 就好了。
7.target ‘NotificationService’ do /platform :ios, “10.0”/pod ‘GTExtensionSDK’/end
多个target,导入个推第三方库的时候有问题,到现在还没找到具体原因,用了一种最笨的办法解决,就是把第三方库直接拖到工程中使用,不用pod。
8.上传到fir上面
一开始看到网上的结论,只要输入一行代码就能上传到fir上面,我试了老半天都不行,说让装什么fir_cli,关键是装不上,我没试成功,最后在fir的官网上找到答案http://blog.fir.im/jenkins/ 在Jenkins上安装一个插件就可以了。纠结了好多天总算解决了。