使用 Jenkins 持续集成 iOS 项目时碰到的一些问题

2,315 阅读3分钟

学习 Jenkins 时遇到很多的坑。。。把这些问题记录下来,避免再犯。

Q1

No iOS profile matching '8xxxxxx3@qq.com/yoxxxhu_Distribution' found:  Xcode couldn't find a profile 
matching '8xxxxxx3@qq.com/yoxxxhu_Distribution'. Install the profile (by dragging and dropping it onto 
Xcode's dock item) or select a different one in the General tab of the target editor.
Code signing is required for product type 'Application' in SDK 'iOS 10.3'

A1

  • 1.用 Xcode 打开 iOS 项目,在 【TARGETS】 - 【General】 中不勾选Automatically manage signing
  • 2.如图配置开发证书:

WX20170602-174826@2x.png

WX20170602-174713@2x.png

  • 3.配置完证书之后,需提交代码到 Git 远程仓库,确保 Jenkins 构建时能获取最新的证书配置

还要确保已经将 /Users/管理员用户名/LibraryMobileDevice 文件夹拷贝到了 /Users/Shared/Jenkins/Library 下面


Q2

FATAL: No global development team or local team ID was configured.

A2

  • Team ID 在这里填写,如图:

WX20170602-181236.png

Team ID 应填写这串字符,如图:

WX20170602-181556@2x.png


Q3


error: exportArchive: No valid iOS Development signing identities belonging to team CxxxxxxxxF were found.

Error Domain=IDEDistributionErrorDomain Code=1 "No valid iOS Development signing identities 
belonging to team CxxxxxxxxF were found." 
UserInfo={NSLocalizedDescription=No valid iOS Development signing identities 
belonging to team CxxxxxxxxF were found.}

A3

  • 1.在 Jenkins - 【系统管理】 - 【Keychains and Provisioning Profiles Management】中重新上传 login.keychain :

WX20170605-103630@2x.png

  • 2.填写 Code Signing Identity :

WX20170605-104534@2x.png

  • 3.重新上传 mobileprovision 文件并填写 Provisioning Profiles Directory Path :

WX20170605-103525@2x.png

  • 4.点击 Save 按钮

Password 是 Mac 开机时输入的密码

  • 5.重新配置项目,如图:

WX20170605-105813@2x.png

WX20170605-105837@2x.png

WX20170605-105928@2x.png

WX20170605-105955@2x.png


Q4

No profiles for 'com.Gxxxxxc.SxxxM' were found:  Xcode couldn't find a 
provisioning profile matching 'com.Gxxxxxc.SxxxM'.
Code signing is required for product type 'Application' in SDK 'iOS 10.3'

A4

/Users/管理员用户名/LibraryMobileDevice 文件夹拷贝到 /Users/Shared/Jenkins/Library 下面


Q5

执行自动上传IPA到蒲公英的脚本时出错 fastlane: command not found

[H20170531_OCUnit] $ /bin/sh -xe /var/folders/9d/jrxjl4_14tj1w33z34jkrxjm0000gn/T/hudson4176251309376324428.sh
+ IPANAME=H20170531_OCUnit
+ fastlane gym --export_method ad-hoc --output_name H20170531_OCUnit
/var/folders/9d/jrxjl4_14tj1w33z34jkrxjm0000gn/T/hudson4176251309376324428.sh: 
line 3: fastlane: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

A5

蒲公英 - 文档中心的解答:

这个情况一般是由于 jenkins 没有设置正确的 $PATH 环境变量导致的。正确设置的方法为:

  • 1.在命令行下执行 echo $PATH,记录下输出的结果
  • 2.在 jenkins 中系统管理-系统设置中,找到 环境变量(Environment variables)
  • 3.在 key 中填写 $PATH,在 value 中填写第一步中输出的结果
  • 4.保存即可

蒲公英 - 文档中心链接: www.pgyer.com/doc/view/je…

  • 但是我按照蒲公英的方法操作之后,还是报这个错误 fastlane: command not found
  • 待解决 ...

Q6

Check dependencies
The file “Pods-Swarm_swift.release.xcconfig” couldn’t be opened because there is no such file.
 (/Users/HW/.jenkins/workspace/SWARM/Pods/Target Support Files/Pods-Swarm_swift/Pods-Swarm_swift.release.xcconfig)

------

diff: /../Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. 
Run 'pod install' or update your CocoaPods installation.

** ARCHIVE FAILED **

The following build commands failed:
	PhaseScriptExecution [CP]\ Check\ Pods\ Manifest.lock /Users/HW/Library/Developer/Xcode/
DerivedData/Swarm_swift-gttgnsxyltckdlfnjucunmsdhnyx/Build/Intermediates/ArchiveIntermediates/
Swarm_swift/IntermediateBuildFilesPath/Swarm_swift.build/Release-iphoneos/Swarm_swift.build/
Script-E66BF0AC51C3B26C2CF625AA.sh

A6

  • 在构建中添加 pod install 脚本:
#!/bin/bash -l
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
pod install --verbose --no-repo-update

此 shell 脚本要放在 Xcode 之前,如图:

WX20170605-170913.png


Q7

iOS 项目使用了 Cocoapods 时,执行 pod install 脚本报错:pod: command not found

+ pod install --verbose --no-repo-update
/var/folders/9d/jrxjl4_14tj1w33z34jkrxjm0000gn/T/hudson943803671821413828.sh: line 5: 
pod: command not found
Build step 'Execute shell' marked build as failure

A7

修改 shell 脚本如下:

#!/bin/bash -l
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
pod install --verbose --no-repo-update

export 语句将控制台语言环境设置为 UTF-8 格式,避免出现 Podfile 文件打开错误。


Q8

ERROR: Timeout after 10 minutes
ERROR: Error cloning remote repo 'origin'

A8

如图:

WX20170605-173713@2x.png


Q9

FATAL: Failed to copy /Users/Shared/Jenkins/Home/kpp_upload/SWARM_Development.mobileprovision to
/Users/HW/Library/MobileDevice/Provisioning Profiles/54xxxxxxxxxxd4.mobileprovision

java.io.FileNotFoundException: 
/Users/HW/Library/MobileDevice/Provisioning Profiles/54xxxxxxxxxxd4.mobileprovision 

A9

  • 开放 /Users/HW/Library/MobileDevice/Provisioning\ Profiles 文件夹的读写权限

WX20170606-151737@2x.png