持续集成之jenkins打包iOS

2022-06-30 14:45:00 浏览数 (1)

1、安装jdk并配置JAVA_HOME

vi ~/.bash_profile

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home

source ~/.bash_profile

2、安装Tomcat

3、下载jenkins.war,部署到tomcat中

4、配置.bash_profile

export JENKINS_HOME=/Users/Shared/Jenkins/Home

5、安装jenkins相关插件:系统管理-->插件管理

Subversion Plug-in 版本控制

Xcode integration xcode打包命令

Keychains and Provisioning Profiles Management管理证书和授权文件

6、配置证书及pfofile:系统管理-->Keychainsand Provisioning Profiles Management

Keychians配置:

打开终端窗口输入命令行

open /Users/管理员用户名/Library/Keychains

例如:open /Users/admin/Library/Keychains

Mac系统10.12版本以后找到 login.keychain-db文件(Mac系统10.12版本之前找到login.keychain文件)(PS:若版本对应的文件没有,选择其中一个文件复制到桌面改名)? ? 将其复制到桌面,回到Jenkins网页,选择文件(桌面的login.keychain-db 或 login.keychain)点击Upload login.keychain-db需要重命名为login.keychain

上传login.keychain文件(管理员用户也就是苹果电脑的登录用户)

配置Code Signing Identity(所使用的签名),开发苹果APP有一个p12的证书。把该证书上传到苹果电脑;双击安装该证书(http://blog.csdn.net/phunxm/article/details/42685597),安装后打开Launchpad,找到钥匙串访问

打开钥匙串访问可以找到Code Signing Identity(所使用的签名)

备注:如果不知道具体填什么可以到钥匙串访问中寻找 iPhoneDistribution:开头的所使用的证书,然后选中后点击右键选择显示简介,在弹出的窗口中找到常用名称,将其复制填入即可;或者可以在命令行中输入security find-identity -p codesigning -v来查找iPhoneDistribution:开头的签名即可,找到后将双引号中的内容复制。

填写完毕如下图:

Provisioning Profiles配置:

找到Provisioning Profiles 文件点击上传

设置 Provisioning ProfilesDirectory Path Provisioning 文件的存放目录;例如把mobileprovision存放在苹果电脑的如下目录

安装xcode和Command Line Tools

Xcode文件很大请自行安装

运行/usr/bin/xcodebuild出现如下错误:

xcode-select:error: tool 'xcodebuild' requires Xcode, but active developer directory'/Library/Developer/CommandLineTools' is a command linetools instance

以上错误是因为安装了 xcode , 但并不是系统默认的位置, 所以可以使用以下命令把 xcode 的路径修改为你安装的位置即可 sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer 红色部分就是你安装的 xcode 的自定义路径。

在终端中输入以下命令安装Command Line Tools:

xcode-select--install

配置Apple Development Teams:系统管理-->系统配置

7、创建苹果App构建

新建Item

配置svn

设置Keychainsand Code Signing Identities和Mobile Provisioning Profiles

构建

有两种方式打包,一是用Xcode插件打包,二是用Shell脚本打包。

方式一用Xcode插件打包:

添加构建步骤-> Xcode基本信息

这里Target请于Xcode项目中Target的名字对应

Clean before build设置为YES

Configuration我选择了Release(在Release的时候Archive)

Output directory为.ipa的输出路径,我这里设置为/Users/Shared/Jenkins/Home

General build settings

Target:就是我们在项目中建立的Target

如果不清楚有哪些Target的情况下可以到xcodeproj或xcworkspace的目录下运行如下命令 xcodebuild -list 即可看到Targets,其中是所有可以用的target。

Pack application, build andsign .ipa?

Code signing & OS X keychain options

设置Development Team

设置Advanced Xcode build options

注解:Xcode SchemaFile构建环境(项目target名称)、Xcode Workspace File:(如果有使用Cooapods管理三方库才填Xcode Workspace File,若没有三方管理库就填Xcode Project File,二者选一)${WORKSPACE}/工程名、Build output directory第三方库存放打包的地方

其他可用查看链接

http://www.jianshu.com/p/5cad74906159

http://www.jianshu.com/p/ce36997919b4

http://www.jianshu.com/p/91e8f571fc2b

http://blog.csdn.net/youtk21ai/article/details/48719807

http://blog.csdn.net/qq_30513483/article/details/51098657

http://www.jianshu.com/p/54c7daae6c94

http://www.jianshu.com/p/371595ef08fe

http://www.jianshu.com/p/382596b1f120

http://www.jianshu.com/p/7a2efc7c69fe

http://www.jianshu.com/p/c69deb29720d http://blog.csdn.net/zhonggaorong/article/details/51436275

http://blog.csdn.net/think12/article/details/76130200

http://blog.csdn.net/u013602835/article/details/54632843

遇到的问题

https://www.cnblogs.com/qingjoin/p/3929493.html

JenkinsXcode 证书设置错误 Code Signerror: No matching codesigning identity found: No codesigning identities

Jenkins集成Xcode项目的时候在证书上遇到了问题。实际上如果在本地的话。只要Xcode工程里选择了项目就不需要重新设置证书了。jenkins会自动找到这个证书,只要在build setting 里设置的是正常的。 并且在xcode 里能正常编译。 Check dependencies

CodeSign error: No codesigning identities found: No codesigning identities (i.e.certificate and private key pairs) that match the provisioning profilespecified in your build settings (“qingyunDeveloper”) were found. 如果遇到类似的错误 解决办法: 首先打开keychain keys 找到apple 的开发者证书。然后复制。再选择左边的系统(system)把刚复制的证书放进去。 如果这个还没有解决。 接下来第二步: 找到你用户下的Provisioning Profiles 文件。目录为 /Users/xxx/Library/MobileDevice/Provisioning Profiles xxx表示你自己的用户名

把这里面所有的证书复制到/Users/Shared/Jenkins/Library/MobileDevice/Provisioning Profile 这个文件。 最后提示

iPhone.build/ProjectCos.xcent/Users/chenqing/Sqy/iOSProject/cyou/Svn/Cos/CosXCode_lxh/build/ProjectCos.app

**BUILD SUCCEEDED **

Finished:SUCCESS 参考资料:

http://code-dojo.blogspot.co.uk/2012/09/fix-ios-code-signing-issue-when-using.html

Fixthe iOS code signing issue when using Jenkins

Thisweek I setup the Jenkins on my Mac and try to build iOS applications.unfortunately I got the code signing issues, either I use xcode plugin or xcodecommand line tool. Through a couple days of googling and I could not find anysolution that works for me, but I finally solve this issue by myself throughdifferent try out, and the solution is such an easy, now I would like to sharewith my solution. The core reason is Jenkins is running as daemon mode in Mac, just assume it isa different user - "Jenkins", so it will not have access to thekeychain or provision profile as a you login using your credentials, whichcause the code signing issue. I found I have following 2 errors 1. "Code Sign error: There are no valid certificate/private key pairs inthe default keychain" Solution: Copy your iPhone developer certificate from "login"keychain to "System" keychain. Detailed steps: open the "Keychain Access" application, click the login tab,right click the certificate like "iPhone Developer: your_name(XXXXXXX)", choose copy, then click the "System" tab, rightclick mouse, choose "Paste 2 items"; you might need to do the samething with the certificate like "iPhone Distribution: your_name". After doing this, you will get the second error. 2. "Code Sign error: Provisioning profile 'xxxxx-xxxx-xxxx-xxxxx' can't befound" Solution: Copy the provision profile to Jenkins user folder. The provision profile is under in the folder /YourUserName/Library/MobileDevice/Provisioning Profiles, for example in my machine, the provision profile files are under/Users/steve/Library/MobileDevice/Provisioning Profiles In the mac, the Jenkins will be in /Users/Shared/Jenkins, create the followingfolder: /Users/Shared/Jenkins/Library/MobileDevice/Provisioning Profile, thencopy the .mobileprovision file to this folder. After doing this, the code signing issues will be fixed. Hope my finding willbe helpful to other Jenkins users.

http://www.jianshu.com/p/5591fe0c6770

http://www.jianshu.com/p/62fa8083b45c

Checkdependencies

Noprofile matching 'XC iOS: com.ios.demo' found:Xcode couldn't find a profilematching 'XC iOS: com.ios.demo'. Install the profile (by dragging and droppingit onto Xcode's dock item) or select a different one in the General tab of thetarget editor.

Codesigning is required for product type 'Application' in SDK 'iOS 10.2'

解决方法:

/Users/【当前登陆用户的用户名】/Library/MobileDevice/的整个文件夹Provisioning Profiles拷贝到/Users/Shared/Jenkins/Library/MobileDevice下面

一定要把Provisioning Profiles整个文件夹放到MobileDevice下面

Jenkins.pkg安装注意步骤:

cat /Users/Shared/Jenkins/Home/secrets/initialAdminPassword 提示权限[Permission Denied]

sudo cat /Users/Shared/Jenkins/Home/secrets/initialAdminPassword

使用root权限打开,否则密码不可见

启动

sudo launchctl load/Library/LaunchDaemons/org.jenkins-ci.plist

停止

sudo launchctl unload/Library/LaunchDaemons/org.jenkins-ci.plist

http://debugtalk.com/post/iOS-Android-Packing-with-Jenkins/

http://debugtalk.com/post/iOS-Android-Packing-with-Jenkins-details/

0 人点赞