一、Jenkins安装
1.进入Jenkins的官网https://jenkins.io/index.html,然后下载并Jenkins war包
2.cd到jenkins.war的目录,终端运行命令 java -jar jenkins.war --httpPort=8080
3.然后可以按照http://www.cocoachina.com/ios/20170811/20218.html配置jenkins
4然后构建的时候会报如下错误
error:exportArchive:"APPNAME.app"requires a provisioning profile with the Push Notifications feature.
Error Domain=IDEProvisioningErrorDomain Code=9""APPNAME.app" requires a provisioning profile with the Push Notifications feature."UserInfo={NSLocalizedDescription="APPNAME.app"requires a provisioning profile with the Push Notifications feature., NSLocalizedRecoverySuggestion=Add a profile to the"provisioningProfiles"dictionaryinyour Export Options property list.}
** EXPORT FAILED **
Failed to build /Users/Tolecen/.jenkins/workspace/APPNAME/build/APPNAME_release.ipa
Build step'Xcode'marked build as failure
Finished: FAILURE
因为 Xcode 9 默认不允许访问钥匙串的内容,必须要设置 allowProvisioningUpdates 才会允许,但是由于 Xcode integration 插件封闭,并不能对其进行修改加上这个属性,所以决定使用 Shell 脚本代替插件
xcodebuild -archivePath "$WORKSPACE/build/appName.xcarchive" -workspace $WORKSPACE/appName.xcworkspace -sdk iphoneos -scheme "appName" -configuration "Debug" archive
xcodebuild -exportArchive -archivePath "/Users/usename/.jenkins/workspace/mmfinance/build/Debug-iphoneos/appName.xcarchive" -exportPath "/Users/jorgon/.jenkins/workspace/appName/build/mmFinance_debug" -exportOptionsPlist '/Users/jorgon/.jenkins/workspace/mmfinance/build/ExportOptions.plist' -allowProvisioningUpdates
注意archivePath,workspace的地址要与自己项目的路径匹配,可以打开jenkins的workspace目录查看/Users/username/.jenkins/workspace
下面附上我的完成shell
#bin/bsah - l
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
cd $WORKSPACE/appname
/usr/local/bin/pod update --verbose --no-repo-update
# 设置版本号
/usr/libexec/PlistBuddy -c 'Set :CFBundleVersion '${VERSION_CODE} ${WORKSPACE}/appname/info.plist
/usr/libexec/PlistBuddy -c 'Set :CFBundleShortVersionString '${VERSION_NAME} ${WORKSPACE}/appname/info.plist
# clean
echo "================= Clean一下 ================="
xcodebuild clean -workspace $WORKSPACE/appname.xcworkspace \
-configuration "Debug" \
-scheme "appname" \
#-alltargets
echo "================= Clean一下 Over ================="
xcodebuild -archivePath "$WORKSPACE/build/Debug-iphoneos/appname.xcarchive" -workspace $WORKSPACE/appname.xcworkspace -sdk iphoneos -scheme "appname" -configuration "Debug" archive
xcodebuild -exportArchive -archivePath "/Users/username/.jenkins/workspace/appname/build/Debug-iphoneos/appname.xcarchive" -exportPath "/Users/jorgon/.jenkins/workspace/appname/build/mmFinance_debug" -exportOptionsPlist '/Users/jorgon/.jenkins/workspace/appname/build/ExportOptions.plist' -allowProvisioningUpdates
#蒲公英上的User Key
uKey="f4557f8d1d7dcaa885d3d0f865d7209"
#蒲公英上的API Key
apiKey="ddddb5c605442a472ae61728d4f643"
#要上传的ipa文件路径
IPA_PATH="${WORKSPACE}/build/mmFinance_debug/appname.ipa"
#密码
PASSWORD=123456
MSG=`git log -1 --pretty=%B`
#执行上传至蒲公英的命令
echo "++++++++++++++upload+++++++++++++"
curl -F "file=@${IPA_PATH}" -F "uKey=${uKey}" -F "_api_key=${apiKey}" -F "updateDescription=${MSG}" -F "password=${PASSWORD}" http://www.pgyer.com/apiv1/app/upload
构建后发送邮件配置
构建后提示邮件发送成功可是没收到邮件
不要勾选这两项,勾选了反而不能发送邮件了
参考链接:
http://www.cocoachina.com/ios/20170811/20218.html
http://blog.csdn.net/hou_manager/article/details/78201221?locationNum=10&fps=1
https://testerhome.com/topics/10154