iOS持续集成—Jenkins(最新最全)

搭建Jenkins前,请确认mac系统上已经搭建好了Java环境。
从零开始一步一步构建,遇到了很多坑,好在最终success了。

一、 搭建Jenkins

1. 安装Jenkins

官网上下载pkg安装包

这里以jenkis-2.73.3.pkg包为例

安装完成后,Safari可能会自动打开,如果没有自动打开,打开浏览器,输入http://localhost:8080
如果页面提示不能连接服务器的错误,重启电脑。然后再输入http://localhost:8080进入登录页面。
根据提示,找到/Users/Shared/Jenkins/Home/ 这个目录,找到secrets文件,显示简介,设置所有人都可以读与写的权限,并找到initialAdminPassword文件,同样放开权限,复制出密码,登录进去,一路安装过来,输入用户名、密码、邮件等。最后点击Save and Finish。

注意:如果安装之后发现密码忘记了,从initialAdminPassword文件中复制输入也错误,试了很多方法也不管用,那就卸载重装Jenkis然后重启电脑吧。

2. 拷贝文件

2.1

将/Users/用户名/Library的MobileDevice文件夹拷贝到/Users/Shared/Jenkins/Library下

注意:是将MobileDevice这个文件夹拷贝过去,而不是MobileDevice里的文件,/Users/Shared/Jenkins/Library 目录下是没有MobileDevice这个文件夹,所以先创建一个MobileDevice文件夹。

在终端输入:

sudo mkdir /Users/Shared/Jenkins/Library/MobileDevice
sudo cp -r /Users/xxx/Library/MobileDevice/ /Users/Shared/Jenkins/Library/MobileDevice/

注意:曾遇到/Users/xxx/Library/下没有MobileDevice文件夹,原来是新机上没有安装Xcode。

2.2

将/Users/用户名/Library/Keychains/下的login.keychain及login.keychain-db这两个文件拷贝到/Users/Shared/Jenkins/Library/Keychains文件夹下面

注意:Mac OS 10.12以下的没有login.keychain-db这个文件,只需要拷贝login.keychain文件。

在终端输入:

cd /Users/Shared/Jenkins/Library/
sudo mkdir Keychains
sudo cp /Users/xxx/Library/Keychains/login.keychain ./Keychains/
sudo cp /Users/xxx/Library/Keychains/login.keychain-db ./Keychains/

再将这个login.keychain拷贝到桌面上

在终端输入:

sudo cp /Users/jiekangwei/Library/Keychains/login.keychain ~/Desktop/

注意:如果/Users/xxx/Library/Keychains/目录下没有login.keychain这个文件,就复制login.keychain-db文件到指定目录,然后将复制在桌面上的该文件改后缀为.keychain。

3. 钥匙串权限、~/Library权限以及电脑用户管理权限

3.1

打开钥匙串,找到相应的证书

右键密钥显示简介,在访问控制那一项里勾选允许所有应用程序访问此项目,并存储更改。

3.2

找到Library资源库文件夹,设置共享与访问权限,everyone读与写都可以


3.3

进入mac系统偏好设置 — 用户与群组 — 其他用户 — jenkins ,勾选允许用户管理这台电脑,并右键选择高级选项,将名字改为jenkins

4. Jenkins插件及系统设置

进入管理插件,在可选插件里所有关键字,下载安装插件Keychains and Provisioning ProfilesManagement和 Xcode integration

4.1

选取拷 在桌上login.keychain以及项 相对应的Provisioning Profile 并upload

注意:开发证书和provision profile 一定要对应正确,不然命令行打包会认证不了而失败

password 一定要填写正确的钥匙串的密码

Code Signing Identity 是从钥匙 找到相应的证书,然后显示简介复制 来,这 Identities 少要填 两项,是因为这 放 个的话后 的设置 Code Signing Identity 能 动对应上。

Provisioning Profiles Directory Path 这 项 填写/Users/用户名/Library/ MobileDevice/Provisioning Profiles

注意:路径里Provisioning Profiles是Provisioning\ Profiles

点击Save

4.2

安装完Xcode integration后进 系统设置。

Xcode Builder

填写钥匙串密码

5. 新建

5.1

填写名字,选择构建自由风格,点击ok


进入Project,进入配置

5.2

General

项目名称,这里可以和git项目名称一样,也可以另起一个名称。

5.3

源码管理

选择git,然后在Repository URL 上填写git仓库地址


选择add

选择SSH Username with private key
Username 为上传到git的用户名,Private Key从id_rsa文件里复制出来


5.4

构建触发器,可选填

5.5

构建环境

选择Keychains andProvisioning Profiles Management和Mobile Provisioning Profiles


Code Signing Identity 第一次不能自动显示出来没关系,保存,然后第二次进来就自动选上了。

5.6

构建

有两种打包方式,一是用Xcode打包,而是用Shell脚本打包,当Xcode版本为9或者以上,应该使用Shell脚本打包。

因为 Xcode 9 默认不允许访问钥匙串的内容,必须要设置 allowProvisioningUpdates 才会允许,但是由于 Xcode integration 插件封闭,并不能对其进行修改加上这个属性,所以使用 Shell 脚本代替插件。

5.6.1
这里先介绍Xcode打包,项目使用的是Xcode 8.1

General build settings

这里Target请于Xcode项目中Target的名字对应
Clean before build设置为YES
Configuration选择Release)
Output directory为.ipa的输出路径,可选填

Code signing & OS X keychain options

teamId 为对应证书括号里面有,如果没找到,请在苹果开发网站登陆进去,从Membership上查看。选择Unlock Keychain,填写钥匙串密码

Advanced Xcode build options

Xcode Schema Files 填写Xcode项目的schema
因为项目含有Workspace,所以填写Xcode Workspace File,填写该项目xcworkspace文件的绝对路径
Build output directory 填写${WORKSPACE}/build/ ,这里注意是大括号


打开工程,mange schemes,勾选项目schemes对应的shared,该scheme为填写的Xcode Schema Files的内容


ok,点击保存,使用Xcode构建配置完毕

5.6.2

选择Execute shell 打包


command 写入脚本:

xcodebuild clean -workspace 工程名称.xcworkspace -scheme 工程名称 -configuration Release

xcodebuild archive -workspace 工程名称.xcworkspace -scheme 工程名称 -archivePath 工程名称.xcarchive

xcodebuild -exportArchive -archivePath 工程名称.xcarchive -exportOptionsPlist /Users/用户名/ExportOptions.plist -allowProvisioningUpdates -exportPath ./

ExportOptions.plist 注意大小写,先打包工程,将ExportOptions.plist文件拷贝到/Users/用户名/或者指定的目录,记得脚本中/Users/用户名/ExportOptions.plist 对应的是该文件的路径。




Next ,然后Export



6. 上传

这里把项目上传到fir.im平台为例

之前选择使用命令行

但遗憾的是用终端安装fir-cli总是失败,于是就选择使用fir.im插件

这里选择使用fir.im插件, 进入 官网下载,下载jenkins插件

然后进入Jenkins,选择插件管理 — 高级

选择下载好的fir-plugin-1.9.5.hpi,上传并安装完后

进入项目的配置页面,在构建后操作里选择Upload to fir.im,填写fir.im token


好了,点击保存,立即构建吧

如果构建时后台打印出以下信息,恭喜你,你构建成功了


二、配置Jenkins错误

1、 拷贝文件错误

Failed to copy /Users/Shared/Jenkins/Home/kpp_upload/xxxx.mobileprovision to /Users/xxx/Library/MobileDevice/Provisioning Profiles/xxxx.mobileprovision

解决:文件拷贝失败。1.查看Library读写权限是否开放;2. 查看系统管理 — Keychains and Provisioning Profiles Management,查看Provisioning Profiles Directory path 是否有误

2、 证书文件找不到

Check dependencies Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning profile with the UUID “75025357-245d-448b-9343-96148a0xxxxx”, however, no such provisioning profile was found.

解决:将/Users/管理员用户名/Library下的MobileDevice文件夹拷贝到/Users/Shared/Jenkins/Library下面

security: SecKeychainUnlock login.keychain: The user name or passphrase you entered is not correct. FATAL: Unable to unlock the keychain.

解决:确认钥匙串密码是正确的

4、 pod没有权限

/Users/xxx/workspace/xxxx/Pods/Target Support Files/Pods-xxxx/Pods-xxxx-resources.sh: line 7: /Users/xxx/workspace/xxxx/Pods/resources-to-copy-DiscoverPanjin.txt: Permission denied

解决:在终端打开项目目录并输入 sudo chmod 777 Pods

5、 使用fir插件上传失败

ERROR: Can not found mapping or dysm file in /Users/Shared/Jenkins/Home/jobs/xxxx/workspace. Deployment failed : Error while get details for update id = xxxxx Build step 'Upload to fir.im' marked build as failure

解决:fir插件版本过低,使用最新fir插件试试

6、使用命令行上传失败

fir p/Users/Shared/Jenkins/Home/jobs/xxx/workspace/build/xxx.ipa -T 4dc6d4c3ebe1969b3c76353514xxxxx /Users/Shared/Jenkins/tmp/jenkins3233517671203652013.sh: line 2: fir: command not found Build step 'Execute shell' marked build as failure

解决:没有安装fir-cli命令

7、

Will not set default: file /Users/Shared/Jenkins/Library/Keychains/login.keychain-db is owned by UID=0, but we have UID=262 security: SecKeychainSetDomainDefault user: write permissions error

解决:进入mac 系统偏好设置 — 用户与群组 — 其他用户 — jenkins ,勾选允许用户管理这台电脑

8、

FATAL: Failed to mkdirs: /Users/xxx/Desktop/ipa java.io.IOException: Failed to mkdirs: /Users/xxx/Desktop/ipa

解决:Output directory 路径错误

9、

FATAL: Build directory does not exist at /$(WORKSPACE)/build. Potential configuration issue. Build step 'Xcode' marked build as failure

解决:Build output directory 填写错误,正确为${WORKSPACE}/build

10、

== Available schemes [workspace] $ /usr/bin/xcodebuild -list -workspace /Users/xxx/workspace/xxxx.xcworkspace xcodebuild: error: '/Users/xxx/workspace/xxxx.xcworkspace' does not exist.

解决:Xcode Workspace File 路径错误

11、

rror Domain=IDEProfileLocatorErrorDomain Code=1 "No profiles for 'xxxxxxx' were found" UserInfo={NSLocalizedDescription=No profiles for 'xxxxxxx' were found, NSLocalizedRecoverySuggestion=Xcode couldn't find any iOS Ad Hoc provisioning profiles matching 'xxxxxxx'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild.

解决:打包工程导出ipa时选择手动选择证书

12、

+ xcodebuild -exportArchive -archivePath /xxx.xcarchive -exportPath -exportOptionsPlist /Users/xxx/exportOptionsPlist.plist
xcodebuild: error: The flag -exportOptionsPlist is required when specifying -exportArchive.
Build step 'Execute shell' marked build as failure

解决:拷贝到指定路径的ExportOptions.plist 名称大小写错误

13、

create and update profiles, app IDs, and certificates. For manually signed targets, xcodebuild will download missing or updated provisioning profiles. Requires a developer account to have been added in Xcode's Accounts preference pane. -allowProvisioningDeviceRegistration Allow xcodebuild to register your destination device on the developer portal if necessary. This flag only takes effect if -allowProvisioningUpdates is also passed. Build step 'Xcode' marked build as failure

解决:脚本上缺少allowProvisioningUpdates这一句

14、

$ /usr/bin/xcodebuild -scheme xxxx -workspace /Users/用户名/workSpace/xxxx/xxx.xcworkspace -configuration Release clean archive -archivePath "/Users/Shared/Jenkins/Home/workspace/xxx/build/xxxx.xcarchive" "BUILD_DIR=/Users/Shared/Jenkins/Home/workspace/xxx/build/" DEVELOPMENT_TEAM=EFL2T3NT3W -exportArchive -exportPath /Users/Shared/Jenkins/Home/workspace/xxx/build/ -exportOptionsPlist /Users/xxx/options.plist
xcodebuild: error: The flag -scheme cannot be specified along with -exportArchive.

或者

[iOS Panjin] $ /bin/sh -xe /Users/Shared/Jenkins/tmp/jenkins410183735701877848.sh
+ echo '================= Clean一下 ================='
================= Clean一下 =================
+ xcodebuild clean -workspace .xcworkspace -configuration -target
xcodebuild: error: If you specify a workspace then you must also specify a scheme.  Use -list to see the schemes in this workspace.
Build step 'Execute shell' marked build as failure
Build step 'Xcode' marked build as failure

或者:

[iOS xxx] $ /bin/sh -xe /Users/Shared/Jenkins/tmp/jenkins8239787762841783385.sh
+ xcodebuild clean -workspace .xcworkspace -scheme -configuration
xcodebuild: error: '.xcworkspace' does not exist.
Build step 'Execute shell' marked build as failure

或者:

+ xcodebuild -exportArchive -archivePath /xxx.xcarchive -exportOptionsPlist /Users/xxx/ExportOptions.plist -allowProvisioningUpdates -exportPath ./
error: archive not found at path '/xxx.xcarchive'
Build step 'Execute shell' marked build as failure

解决:用脚本构建时,脚本输写有误

15、

+ xcodebuild -exportArchive -archivePath xxxx.xcarchive -exportOptionsPlist /Users/xxx/ExportOptions.plist -allowProvisioningUpdates -exportPath ./
error: archive not found at path '/Users/Shared/Jenkins/Home/workspace/xxx/xxx.xcarchive'
** EXPORT FAILED **

Build step 'Execute shell' marked build as failure

解决: /Users/Shared/Jenkins/Home/workspace/ 下.xcarchive 文件名称有误,或者.xcarchive文件路径有误

16、

Error Domain=IDECodesignResolverErrorDomain Code=1 "No certificate for team 'xxxxx' matching 'DB8C944F71D475DE773696BD637xxxxxxx' found" UserInfo={IDEProvisioningError_UserInfoKey_IDEProvisioningErrorSpecifier=DB8C944F71D475DE773696BD6374C5xxxxx, NSLocalizedDescription=No certificate for team 'xxxxx' matching 'DB8C944F71D475DE773696BD6374C5BBxxxxxxx' found, NSLocalizedRecoverySuggestion=Specify a different signing certificate for "signingCertificate" in your Export Options property list., IDEProvisioningError_UserInfoKey_IDEProvisioningErrorTeam=<IDEProvisioningBasicTeam 0x7fee800853e0: teamID: xxxxxx, teamName: (null)>, IDEProvisioningError_UserInfoKey_IDEProvisioningErrorPlatform=com.apple.platform.iphoneos, IDEProvisioningError_UserInfoKey_IDEProvisioningErrorAction=5}

解决:keychains下的provisioning profile 对应不上 certificate证书,把钥匙串相应的证书删掉,重新从苹果商店下载证书和provisioning profile,在Jenkis —系统设置— Keychains and Provisioning Profiles Management插件里全部删除,执行前文 2、拷贝文件 操作,然后upload新的login.keychain和provisioning profile

关注微信公众号:iOSSir,每日更新苹果资讯、技术干货!


公众号二维码.jpg

原文地址:https://www.jianshu.com/p/9cb3d8c8c78d

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,117评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,328评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,839评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,007评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,384评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,629评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,880评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,593评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,313评论 1 243
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,575评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,066评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,392评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,052评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,082评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,844评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,662评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,575评论 2 270

推荐阅读更多精彩内容