Jenkins是个比较方便持续集成的工具,简单记录一下利用Jenkin拉取SVN的iOS代码,并且打包上传到蒲公英(fir.im类似)的过程。安卓只需要安装对应的插件就可以。可以实现定时打包发布任务,方便自动化管理。考虑到现在代码基本往Git上迁移,在第八步给出快捷迁移SVN代码到Git的方法。
一、安装Jenkins
下载pkg文件
安装后会自动打开http://localhost:8080
第一次的初始密码在initialAdminPassword
文件中
/Users/Shared/Jenkins/Home/secrets/initialAdminPassword
也可以使用Homebrew
安装
brew install jenkins
$ brew update && brew outdated jenkins
$ brew cask install java
$ ln -sfv /usr/local/opt/jenkins/*.plist ~/Library/LaunchAgents
$ sudo cp -fv /usr/local/opt/jenkins/*.plist /Library/LaunchDaemons
$ sudo chown `whoami` /Library/LaunchDaemons/homebrew.mxcl.jenkins.plist
参考installing-jenkins-os-x-homebrew
二、选择安装插件
2.1 需要安装的插件:
Xcode integration
Keychains and Provisioning Profiles Management
安装完成后我们重启下jenkins,重新加载下插件。可以滑到最底下勾选重启,或者也可以在地址栏输入http://localhost:8080/restart
重启之后应该要输入用户名和密码,把刚刚注册的用户名密码输入进去。还有一个重要的步骤,我们先给Jenkins用户管理员的权限,避免后续的访问问题。系统偏好设置->用户与群组->点开锁,然后在Jenkins用户下勾选“允许用户管理这台电脑”。到这步最好给Jenkins用户设置一个密码,便于后期检查是否Jenkins配置错误或者是检查代码错误。
三、创建一个item
四、设置基本配置
五、配置SVN
5.1 连接SVN代码库
六、设置打包的签名
这里需要打开 Keychains
插件
Keychains and Provisioning Profiles Management
上传login.keychain
文件,证书和对应的profile
文件
login.keychain
文件路径:
~/Library/Keychains
其中login.keychain-db可以改成login.keychain,然后上传
如果是用Pod管理的,需要打开Scheme共享:
没有打开共享的路径:
$ /Users/developer/Library/Keychains/login.keychain
我这边是用Pod管理的,打开Scheme共享的路径:
$ /Users/Shared/Jenkins/Library/Keychains/login.keychain
在Jenkins的Xcode模板配置如下:
通用路径:
${HOME}/Library/Keychains/login.keychain
6.1 证书
Keychain password
对应的密码可以在钥匙串中查看:
6.2 描述文件Profiles
把Provisioning Profiles
文件放到Jenkins/Library/MobileDeviece/Provision Profiles
文件夹中
然后配置签名和钥匙串的选项
6.3 设置Xcode integration
面板
七、上传到蒲公英
脚本代码:
curl -F "file=@${WORKSPACE}/build/ipa/${JOB_NAME}@${VERSION}@${BUILD_DATE}.ipa"
-F "uKey=uKey" -F "_api_key=_api_key" https://www.pgyer.com/apiv1/app/upload
注:对于Cocoapods
项目,需要设置schemes
为Shared
,不然可能因为找不到scheme
报错
注意点
1、Jenkins 安装成功后,会创建一个Jenkins用户,而Jenkins的工作区间默认是在/用户/共享/Jenkins/Home/jobs
目录下,可以用Finder-->前往
进入。
2、Jenkins目录下的文件夹的读写权限只对Jenkins用户开放,所以后面apple证书等必须在Jenkins用户下安装,项目的ipa导出也得在Jenkins用户下操作。(或者用管理员权限修改该目录针对用户的权限)
3、Jenkins的使用是每一个用户都可以使用,所以有可能导致构建版本的时候报错,还是老老实实在Jenkins用户下操作吧。
常用命令
1)我们先把jenkins停掉,执行:
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
3.第三个坑:打包iOS有pod的项目,shell
执行pod install
时,提示pod command not found
,这个需要在shell
第一行加上 bin/bash -l
就行了,所以最终是这样:
!/bin/bash -l
export LANG=en_US.UTF-8
pod install --verbose --no-repo-update
- 第四个坑:有pod的项目可能提示schema找不到的问题,需要用xcode打开一次.xcworkspace就好了,或者在shell pod install之后下加上 open x.xcworkspace
常见错误
1.Cocoapods打包问题Jenkins:”ResourceRules.plist: cannot read resources” error after Xcode 6.1
error: /usr/bin/codesign --force --preserve-metadata=identifier,entitlements,
resource-rules --sign iPhone Distribution: Certificate--resource-rules=/var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/ctBXHIqC3V/Payload/ProjectName
.app/ResourceRules.plist --entitlements
/var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/ctBXHIqC3V/entitlements_plistUx80j3Iz
/var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/ctBXHIqC3V/Payload/ProjectName.app failed with error 1.
Output: Warning: usage of --preserve-metadata with option "resource-rules" (deprecated in Mac OS X >= 10.10)!
Warning: --resource-rules has been deprecated in Mac OS X >= 10.10!
/var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/ctBXHIqC3V/Payload/ProjectName.app/ResourceRules.plist: cannot read resources
解决方法:
在Custom xcodebuild arguments
处填入:
CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist
错误2 :
Code Sign error: No matching provisioning profile found: Your build settings specify a provisioning profile with the UUID “dc5a6f0d-5d0e-4680-9d07-248d78b4d576”, however, no such provisioning profile was found.
解决方法:
检查后发现SVN上的Code Sign配置并没有和本地的一致,确认后,提交SVN后解决
错误3 :Cocoapods打包
error: /usr/bin/codesign --force --preserve-metadata=identifier,entitlements,resource-rules --sign iPhone Distribution: Certificate--resource-rules=/var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/vDWiCo9Pi6/Payload/ProjectName.app/ResourceRules.plist
--entitlements /var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/vDWiCo9Pi6/entitlements_plistUcV_4_yn /var/folders/ph/2y4lb27j1zx6lcp3htvhnlbm000087/T/vDWiCo9Pi6/Payload/ProjectName.app failed with error 1. Output: Warning: usage of
--preserve-metadata with option "resource-rules" (deprecated in Mac OS X >= 10.10)!
解决方法:
步骤1
nomadshenzhen
步骤2
--resource-rules has been deprecated in mac os x >= 10.10
在Xcode Building Setting的Code Signing Resource Rules Path 中添加
$(SDKROOT)/ResourceRules.plist
错误4: xcodebuild: error: 'APP.xcworkspace' does not exist
Choose Product > Scheme > Manage Schemes.
Share your scheme:
- 缺少scheme
xcodebuild: error: The project named “Foo” does not contain a scheme named “Bar”. The “-list” option can be used to find the names of the schemes in the project.
解决办法:
The root cause is that the default behavior of Schemes is to keep schemes ‘private’ until they are specifically marked as shared. In the case of a command-line initiated build, the Xcode UI never runs and the xcoderun tool doesn’t have its own cache of Schemes to work with.
To your schema be visible for command-line build you must mark it as a shared scheme.
Choose Scheme > Manage Schemes (from the Product Menu).
Ensure the ‘Shared’ box is checked for that scheme
A new .xcscheme file has been created in your project at
WorkspaceName.xcworkspace/xcshareddata/xcschemes.
Commit this file to your repository
八、SVN代码迁移到GIt
方法:
使用Git命令,把SVN上的代码和提交记录clone到本地,然后提交到Git上。
主要命令
git svn clone svn://xxxxxxx/${ProjectName}
--authors-file=user.txt --no-metadata ${ProjectName}
git svn clone svn://xxxxxxx/xxxxxx/xxxxx/trunk/xxxxxx
--authors-file=user.txt --no-metadata ProjectName
8.1 建立User更换表
格式:
SVN账户名 = Git账户名<Git邮箱名>
最后,在Git建立项目仓库, push代码到Git仓库
九、卸载Jenkins
在终端中执行:
'/Library/Application Support/Jenkins/Uninstall.command'
如果老版本命令无效
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
sudo rm /Library/LaunchDaemons/org.jenkins-ci.plist
sudo rm -rf /Applications/Jenkins "/Library/Application Support/Jenkins" /Library/Documentation/Jenkins
如果需要删除已经编译的任务:
sudo rm -rf /Users/Shared/Jenkins
注意
jenkins
是由jar
启动的,需要java
的最新版本
Mac: 通过系统设置中的java
图标启动java
面板,查看java
的版本,
需要升级java
环境
———————— 2017-08-07 ——————
今天重新安装Jenkins
时,在官网下载的Jenkins
2.60,安装后发现一直访问不了默认的http://localhost:8080
,后面发现Jenkins
2.60需要Java
8环境,本地mac还是Java7,但是在jav设置面板升级到8后,貌似制定位置还是7,一直访问不了,后面干脆用Homebrew
安装Jenkins
和Java
8,然后制定端口8080
brew cask install java
brew install jenkins
java -jar jenkins.war --httpPort=8080
在终端输入
jenkins restart
就可以启动jenkins
访问8080
了。
参考
- 手把手教你利用Jenkins持续集成iOS项目
- Mac下Jenkins+SVN+Xcode构建持续导出环境
- mac jenkins iOS持续集成中的坑
- nomadshenzhen
- Jenkins:”ResourceRules.plist: cannot read resources” error after Xcode 6.1
- --resource-rules has been deprecated in mac os x >= 10.10
- installing-jenkins-os-x-homebrew
- IOS 自动化部署 - 最新Jenkins + git +cocoapods + fir - 简书
- macos - How to uninstall Jenkins? - Stack Overflow