之前用的Jenkins 用起来太笨重,后来发现Fastlane 做持续集成挺不错就试了试。脚本打包,然后上传到第三方分发平台,最后发邮件通知某人
Fastlane安装:
系统要求:macOS或 Linux 使用 Ruby 2.0.0及以上版本 终端执行:
sudo gem install fastlane --verbose
确保Xcode安装了最新版本的命令行工具:
xcode-select --install
Fastlane使用:
1:cd 你的项目根目录
2:fastlane init
根据提示,配置你的app
这里需要配置apple id 项目唯一标识等
此时你的项目中已经集成了fastlane
生成脚本
vim build_using_gym.sh
#!/bin/bash
#计时
SECONDS=0
#假设脚本放置在与项目相同的路径下
project_path=$(pwd)
#取当前时间字符串添加到文件结尾
now=$(date +"%Y_%m_%d_%H_%M_%S")
#指定项目的scheme名称
scheme="项目名称"
#指定要打包的配置名
configuration="Adhoc"
#指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development, 和developer-id,即xcodebuild的method参数
export_method='ad-hoc'
#指定项目地址
workspace_path="$project_path/项目名称.xcworkspace"
#指定输出路径
output_path="project_path/APP"
#指定输出归档文件地址
archive_path="$output_path/项目名称_${now}.xcarchive"
#指定输出ipa地址
ipa_path="$output_path/项目名称_${now}.ipa"
#指定输出ipa名称
ipa_name="项目名称_${now}.ipa"
#获取执行命令时的commit message
commit_msg="$1"
#输出设定的变量值
echo "===workspace path: ${workspace_path}==="
echo "===archive path: ${archive_path}==="
echo "===ipa path: ${ipa_path}==="
echo "===export method: ${export_method}==="
echo "===commit msg: $1==="
#先清空前一次build
gym --workspace ${workspace_path} --scheme ${scheme} --clean --configuration ${configuration} --archive_path ${archive_path} --export_method ${export_method} --output_directory ${output_path} --output_name ${ipa_name}
#上传到fir
fir publish ${ipa_path} -T fir_token -c "${commit_msg}"
#输出总用时
echo "===Finished. Total time: ${SECONDS}s==="
执行脚本
./build_using_gym.sh
shell发邮件
有时候会使用脚本完成一系列的自动化工作,工作完成后还需要邮件通知相关人员,此时可以使用第三方的工具:SendEmail,最新版本sendEmail-v1.56.tar.gz
下载地址:http://caspian.dotconf.net/menu/Software/SendEmail/
#!/bin/bash
email_reciver="12313@163.com 123123@126.com"
#发送者邮箱
email_sender=213123123@qq.com
#邮箱用户名
email_username=213123123
#邮箱密码
#使用qq邮箱进行发送需要注意:首先需要开启:POP3/SMTP服务,其次发送邮件的密码需要使用在开启POP3/SMTP服务时候腾讯提供的第三方客户端登陆码。
email_password=ieurwor
file1_path="附件一路径"
file2_path="附件二路径"
#smtp服务器地址
email_smtphost=smtp.qq.com
email_title="iOS客户端更新"
email_content="谢谢!"
./sendEmail -f ${email_sender} -t ${email_reciver} -s ${email_smtphost} -u ${email_title} -xu ${email_username} -xp ${email_password} -m ${email_content} -a ${file1_path} ${file2_path} -o message-charset=utf-8
持续集成中遇到的一些问题
1: {"code":501,"message":"Unknown method","data":[]} curl: (6) Could not resolve host: APP 上传API地址错误
2: curl: (26) couldn't open file 上传应用时候 应用路径不对
3: {"code":2,"message":"Data of file can not be empty","data":[]}===Finished 应用路径不对 少@
4: ./build_using_gym.sh: line 39: gym: command not found
sudo gem install gym
Fetching: gym-2.0.0.gem (100%)
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/gym
sudo gem install gym -n /usr/local/bin
5:ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/xcodeproj
https://github.com/fastlane/fastlane/issues/5313
This likely happens because you updated the rubygems gem of your system ruby installation. The default one that ships with macOS customises the default binary directory, but if you update it to any other version (e.g. by doing gem update —system), you will lose that. sudo gem install fastlane -n /usr/local/bin should work as an alternative.