Jenkins、shell
Select a method of distribution
-
Save for iOS App Store Deployment 保存到本地 准备上传App Store 或者在越狱的iOS设备上使用
-
Save for Ad Hoc Deployment 保存到本地 准备在账号添加的可使用设备上使用(具体为在开发者账户下添加可用设备的udid),该app包是发布证书编译的(The app will be code signed with the distribution certificate.)
-
Save for Enterprise Deployment 这种主要针对企业级账户下 准备本地服务器分发的app
-
Save for Development Deployment 针对内部测试使用,主要给开发者的设备(具体也为在开发者账户下添加可用设备的udid)。该app包是开发证书编译的(The app will be code signed with your development certificate)
-
Include bitcode for iOS content苹果给我们加的东西,加了以后苹果可以在后期重新优化你的二进制文件。你所有提交的二进制都可以拿到,比如存在的热更新、马甲包等(监管)
-
Include manifest for over-the-air installation一般不勾选。允许你发布到某一个html上能够进行安装,比较鸡肋
-
shell脚本打包
#使用方法
if [ ! -d ./IPADir ];
then
mkdir -p IPADir;
fi
#工程绝对路径
project_path=$(cd `dirname $0`; pwd)
#工程名 将XXX替换成自己的工程名
project_name=XXX
#scheme名 将XXX替换成自己的sheme名
scheme_name=XXX
#打包模式 Debug/Release
development_mode=Release
#build文件夹路径
build_path=${project_path}/build
#plist文件所在路径
exportOptionsPlistPath=${project_path}/exportAppstore.plist
#导出.ipa文件所在路径
exportIpaPath=${project_path}/IPADir/${development_mode}
echo "请输入你想法发布的方式 ? [ 1:app-store 2:ad-hoc] "
##
read number
while([[ $number != 1 ]] && [[ $number != 2 ]])
do
echo "笨蛋,只能输入 1 or 2"
echo "请输入你想法发布的方式 ? [ 1:app-store 2:ad-hoc] "
read number
done
if [ $number == 1 ];
then
development_mode=Release
exportOptionsPlistPath=${project_path}/exportAppstore.plist
## 证书名字
else
development_mode=Debug
exportOptionsPlistPath=${project_path}/exportTest.plist
fi
echo '///-----------'
echo '/// 正在清理工程'
echo '///-----------'
xcodebuild \
clean -configuration ${development_mode} -quiet || exit
echo '///--------'
echo '/// 清理完成'
echo '///--------'
echo ''
echo '///-----------'
echo '/// 正在编译工程:'${development_mode}
echo '///-----------'
xcodebuild \
archive -workspace ${project_path}/${project_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${development_mode} \
-archivePath ${build_path}/${project_name}.xcarchive -quiet || exit
echo '///--------'
echo '/// 编译完成'
echo '///--------'
echo ''
echo '///----------'
echo '/// 开始ipa打包'
echo '///----------'
xcodebuild -exportArchive -archivePath ${build_path}/${project_name}.xcarchive \
-configuration ${development_mode} \
-exportPath ${exportIpaPath} \
-exportOptionsPlist ${exportOptionsPlistPath} \
-quiet || exit
# 删除build包
if [[ -d build ]]; then
rm -rf build -r
fi
if [ -e $exportIpaPath/$scheme_name.ipa ];
then
echo '///----------'
echo '/// ipa包已导出'
echo '///----------'
open $exportIpaPath
else
echo '///-------------'
echo '/// ipa包导出失败 '
echo '///-------------'
fi
echo '///------------'
echo '/// 打包ipa完成 '
echo '///-----------='
echo ''
echo '///-------------'
echo '/// 开始发布ipa包 '
echo '///-------------'
if [ $number == 1 ];
then
#验证并上传到App Store
# 将-u 后面的XXX替换成自己的AppleID的账号,-p后面的XXX替换成自己的密码
altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
# appstore 验证你的账号 accout + password
"$altoolPath" --validate-app -f ${exportIpaPath}/${scheme_name}.ipa -u xxxx [-p xxx]
# 双冲验证 : account + specialPassword
"$altoolPath" --upload-app -f ${exportIpaPath}/${scheme_name}.ipa -u xxxx -p xxx
else
echo "请输入你要发布的平台 ? [ 1:fir 2:蒲公英] "
##
read platform
while([[ $platform != 1 ]] && [[ $platform != 2 ]])
do
echo "笨蛋,只能输入 1 or 2"
echo "请输入你要发布的平台 ? [ 1:fir 2:蒲公英] "
read platform
done
if [ $platform == 1 ];
then
#上传到Fir
# 将XXX替换成自己的Fir平台的token
fir login -T xxxx
fir publish $exportIpaPath/$scheme_name.ipa
else
echo "开始上传到蒲公英"
#上传到蒲公英
#蒲公英aipKey
MY_PGY_API_K=xxx
#蒲公英uKey
MY_PGY_UK=xxxx
curl -F "file=@${exportIpaPath}/${scheme_name}.ipa" -F "uKey=${MY_PGY_UK}" -F "_api_key=${MY_PGY_API_K}" https://qiniu-storage.pgyer.com/apiv1/app/upload
fi
fi
echo "\n\n"
echo "已运行完毕>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
exit 0
- specialKey位置 /APP-SPECIFIC PASSWORDS
- 没有开启双重认证不需要specialKey
- 不要忘记修改plist文件
- exportAppstore.plist
- exportTest.plist
- plist文件传送门~~
fastlane
-
安装
$ xcode-select --install //Using RubyGems $ sudo gem install fastlane -NV //Alternatively using Homebrew $ brew cask install fastlane //如出现报错 While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory. //解决方案 $ sudo gem install -n /usr/local/bin fastlane -NV
-
-
可修改文件fastlane/metadata
-
编辑文件fastlane/Fastfile
#Fastfile default_platform(:ios) # 1.4.8 ---> version # 输出路径 # clear + pods # deliver 发布 # gym build 归档 # appstore pgy firim # Xcode 不打开 2.1 version platform :ios do before_all do # 双重认证 + # cocoapods(clean: true,podfile: "./CustomPodfile") ENV["FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"] = "rxpc-vbrs-very-wbrq" cocoapods(use_bundle_exec: FALSE) puts "所有任务执行开始了" end desc "Push a new release build to the App Store" lane :release do increment_build_number(xcodeproj: "自动打包技术.xcodeproj") build_app(workspace: "自动打包技术.xcworkspace", scheme: "自动打包技术") upload_to_app_store end desc "Push a new release build to the 蒲公英" lane :pgyAction do increment_build_number(xcodeproj: "自动打包技术.xcodeproj") build_app(workspace: "自动打包技术.xcworkspace", scheme: "自动打包技术") # 上传之前安装插件 --- 蒲公英 # fastlane add_plugin pgyer # fastlane add_plugin firim # 版本管理插件 # fastlane add_plugin fastlane-plugin-version pgyer(api_key:"6ff0ae70480922d8ff35177a777031f1", user_key:"60082eac0f0db81758d935b63797ceba") end desc "Push a new release build to the firim" lane :firimAction do increment_build_number(xcodeproj: "自动打包技术.xcodeproj") build_app(workspace: "自动打包技术.xcworkspace", scheme: "自动打包技术") firim(firim_api_token:"98578618c48d6812a6509a6a70a251a03f57dc62") end end
-
fastfile完整版
default_platform(:ios)
platform :ios do
before_all do
ENV["FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"] = "rxpc-vbrs-very-wbrq"
cocoapods(use_bundle_exec: FALSE)
puts "所有任务执行开始了"
end
desc "上线 App Store"
lane :release do | options |
#increment_build_number(xcodeproj: ENV['Xcodeproj'])
#build_app(workspace: ENV['Workspace', scheme: ENV['Scheme'])
#upload_to_app_store
end
desc "上线testflight"
lane :beta do | options |
#increment_build_number(xcodeproj: ENV['Xcodeproj'])
#build_app(workspace: ENV['Workspace'], scheme: ENV['Scheme'])
#upload_to_testflight
end
desc "上线蒲公英"
lane :adhoc_pgy do |options|
increment_build_number(xcodeproj:ENV['Xcodeproj'])
//ipa包根据时间走
currentTime = Time.new.strftime("%Y-%m-%d-%H-%M-%s")
logDirectory = "#{currentTime}.ipa"
build_app(
workspace: ENV['Workspace'],
scheme: ENV['Scheme'],
silent: true,
clean: true,
//输出路径
output_directory: ENV['Pgy_Output_Path'],
//ipa输出名字
output_name: logDirectory,
# xcodebuild ios 9
# Xcode9以后描述文件的自更新必须加入这个字段。shell脚本是默认添加上的
export_xcargs: "-allowProvisioningUpdates",
export_method:"ad-hoc")
pgyer(api_key: ENV['Api_Key'],
user_key: ENV['Api_Key'])
end
desc "上线firim"
lane :adhoc_firim do |options|
setup_version_build(options)
build_app(
workspace: ENV['Workspace'],
scheme: ENV['Workspace'],
silent: true,
clean: true,
output_directory: ENV['Firim_Output_Path'],
output_name: "自动打包技术.ipa",
export_xcargs: "-allowProvisioningUpdates",
export_method:"ad-hoc")
firim(firim_api_token:ENV['Firim_Token'])
end
# 函数
desc "版本处理"
def
//传入options处理
//使用
// $ fastlane adhoc_firim version:2.1 build:2
setup_version_build(options)
increment_build_number(
build_number:options[:build]
)
increment_version_number(
version_number:options[:version]
)
end
after_all do |lane, options|
puts"结束了"
end
error do |lane, exception, options|
if options[:debug]
puts "Hi :)"
end
end
end
- 集成fastlane遇到的一些问题
- 常用字段解释
Jenkins
- 持续集成 — 自定义 : 平台 BUG 繁琐 图形图像
- 解决Shell、fastlane在终端输入不便
- iOS Android java web js (项目管理能力)
- 安装地址
- 尽量安装Generic Java package (.war)包
- JDK下载地址
- 启动: java -jar jenkins.war
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
//秘钥
8f0e8a60XXXXXXXXXX676f528e83ed9
This may also be found at: /Users/qionglinfu/.jenkins/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
- http://localhost:8080 然后输入秘钥
- 安装推荐插件
-
Git Parameter 构建过程、选择分支、环境变量
- 源码管理不需要添加全局凭证,一样能过
- Keychains and Provisioning Profiles Management 描述文件的管理
- 托管描述文件,用于编译等操作。需要上传keyChain,存放在/Jenkins/kpp_upload
- 位置:/Users/qionglinfu/Library/Keychains/login.keychain-db 去掉-db后缀存放Jenkins目录下
- 为了管理生产、发布等证书
- 描述文件一定要搞到UUID:证书序列号,自动匹配的
- 执行Shell脚本
- 上传蒲公英需要安装Upload to pgyer
- Xcode上线需要安装Xcode integration
- 安装以后配置/构建选择Xcode
- 配置Team ID
- 多Target需要单独配置Target
- 配置完记得应用一下
- Clean before build 勾选Yes
- Configuration配置Release等环境
- 配置Xcode Schema File
- 勾选Pack application build and sign .ipa
- 配置Export method: App Store
- 配置.ipa filename pattern
- 配置Output directory:输出路径
- keychain options不需要管理签名,前面已经配置好了。选择Unlock Keychain。选择默认路径,输入开机密码,点击应用
- 配置Advanced Xcode build options,勾选Clean test reports,配置Xcode Project Directory: workspace的路径,配置Build output directory: /Users/QionglinFu/Desktop/build/
- 添加插件fir-plugin
- 配置构建后操作
- Upload to fir.im
- 配置token即可
报错解决
- ld: library not found for -lReactiveObjc
- CocoaPods的问题,编译一下即可,执行一下pod install