jenkins在root权限下ios命令打包失败
使用XCode可以正常打包并导出IPA,但是同一台机器上安装的Jenkins就出现问题。
编译时出现error: No certificate for team ‘xxx’ matching ‘iPhone Distribution: xxxxx’ found: Select a different signing certificate for CODE_SIGN_IDENTITY, a team that matches your selected certificate, or switch to automatic provisioning. (in target ‘xxxxx’ from project ‘xxxxx’)

后面Jenkins安装了Keychain and Provisioning Profiles Management插件,把login.keychain文件和profile文件上传后,虽然证书是找到了,但是profile没找到,出现error: No profile for team ‘xxx’ matching ‘xxxx’ found: Xcode couldn’t find any provisioning profiles matching ‘xxxx’. Install the profile (by dragging and dropping it onto Xcode’s dock item) or select a different one in the Signing & Capabilities tab of the target editor. (in target ‘xxxx’ from project ‘xxxx’)

研究了下,应该是Jenkins的启动用户是root权限问题。
首先停止jenkins运行:
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
然后更改/Library/LaunchDaemons/org.jenkins-ci.plist,我使用的vim修改,可根据自己的习惯使用其他方式修改。下面是我的org.jenkins-ci.plist文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>StandardOutPath</key> <string>/Users/xxx/Documents/jenkins/jenkins.log(日志路径)</string> <key>StandardErrorPath</key> <string>/Users/xxx/Documents/jenkins/jenkins.log(日志路径)</string> <key>EnvironmentVariables</key> <dict> <key>JENKINS_HOME</key> <string>/Users/xxx/Documents/jenkins(这里我放把Jenkins的目录放到当前用户的文档目录下,避免各种权限问题)</string> </dict> <key>GroupName</key> <string>staff</string> <key>KeepAlive</key> <true/> <key>Label</key> <string>homebrew.mxcl.jenkins</string> <key>ProgramArguments</key> <array> <string>/usr/libexec/java_home</string> <string>-v</string> <string>1.8</string> <string>--exec</string> <string>java</string> <string>-Dmail.smtp.starttls.enable=true</string> <string>-jar</string> <string>/Users/xxx/jenkins.war(我把jenkins.war也放到外面来)</string> <string>--httpListenAddress=192.168.199.148</string> <string>--httpPort=8086</string> </array> <key>RunAtLoad</key> <true/> <key>UserName</key> <string>当前的用户名</string> <key>SessionCreate</key> <true/> </dict> </plist> |
这里需要注意的是我使用brew来安装的jenkins,所以JENKINS_HOME目录本来是在其它目录下的,我是手动把它移动到Document目录下,所以需要执行
1 |
sudo chown -R 当前用户名:staff 新的JENKINS_HOME的路径 |
最后执行
1 |
sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist |
重新刷新Jenkins页面,使用xcodebuild archive 命令来编译,在最后又出现了其它错误
1 2 |
AFNetworking.framework: errSecInternalComponent Command PhaseScriptExecution failed with a nonzero exit code |
errSecInternalComponent这个错误是查了下是签名机制的问题。
我的解决方式是在Jenkins的Build Shell里面的xcodebuild上一句加多一句代码
1 |
security -v unlock-keychain -p "当前用户的密码" login.keychain |
然后使用以下两句命令导出ipa(把APPNAME按自己实际填写)
1 |
xcodebuild archive -workspace APPNAME.xcworkspace -scheme APPNAME -configuration Release -archivePath ./build/APPNAME.xcarchive |
1 |
xcodebuild -exportArchive -archivePath ./build/APPNAME.xcarchive -exportPath ./build/export/ -exportOptionsPlist ./build/export.plist |
这里要注意一下的是export.plist这个文件,建议手动在XCode打包导出ipa后把那个ExportOptions.plist文件直接拿来用,避免填写错误。