iOS自动化打包 jenkins+svn+命令行打包+fir
安装jenkins
未装过homebrew的参照homebrew主页
使用 homebrew 安装jdk
$brew install Caskroom/cask/java
使用 homebrew 安装 jenkins
$brew install jenkins
安装fir上传命令
$ gem install fir-cli
完成后就可以直接打开http://localhost:8080/如图

jenkins设置
1.安装jenkins插件
点击系统管理->管理插件,在插件管理里面下载几个比较有用的插件,当然可以根据自己的需求增减。


然后等待安装完成就是了,本次用到的插件有
Email Extension Plugin:用于发送邮件,功能比自带的强大
Next Build Number Plugin:修改下次编译的build号
2.新建Item
返回Jenkins主页,点击左上角的新建按钮开始新建一个Item

输入Item的名称,选择构建一个自由风格的软件项目

在源码管理里面选择Subversion,然后配置svn信息

配置参数化内容,如图,可以用${name}
在shell命令中取出对应的值

本次打包中添加了两个参数fir_description、host_distribution
,用来表示发布到fir时的更新日志和打包的host环境

在构建步骤中添加Execute shell,我们通过shell命令进行编译,打包,上传

我的构建步骤分了三步,都在用shell命令完成,当然你也可以写好shell文件放在本地直接执行本地的文件
1.设置build号为jenkins的build号、编译、打包生成ipa文件
2.更新到svn
3.上传到fir

详细代码见文章底部
配置邮件

所有的配置设置完后点应用,再点保存,至此我们已经完全配置完这个item
总结遇到的问题
1.证书找不到
参照http://www.faceye.net/search/81369.html
2.fir上传的描述不能识别中文
原因是shell命令中会使中文乱码,在shell命令前加上
export LANG="en_US.UTF-8"
附shell命令
需要在Xcode中添加In_house_out、In_house_in两个配置项目用于表示内网和外网环境的inhouse包,如果你不需要多个环境的包就不用做参数化配置了

打包命令
#变量
TARGET_NAME="xxxxx"
APPDISPLAY_NAME="xxxxx"
CODE_SIGN="iPhone Distribution: xxxxxxxxxxxx., Ltd."
BUILD_DIR="${WORKSPACE}/build"
IPA_DIR="${WORKSPACE}/ipa"
#环境变量的更改
if ${host_distribution}; then
BUILD_CONFIG="In_house_out"
else
BUILD_CONFIG="In_house_in"
fi
#首先,清除build记录:
xcodebuild clean -workspace $TARGET_NAME.xcworkspace -scheme $TARGET_NAME -configuration $BUILD_CONFIG
#设置build号
xcrun agvtool new-version -all ${BUILD_NUMBER}
#其次,执行build:
xcodebuild -workspace $TARGET_NAME.xcworkspace -scheme $TARGET_NAME -configuration $BUILD_CONFIG build BUILD_DIR=$BUILD_DIR BUILD_ROOT="${WORKSPACE}/buildRoot" CODE_SIGN_IDENTITY="$CODE_SIGN"
#创建输出目录
mkdir -p $IPA_DIR
cp -f -r $BUILD_DIR/$BUILD_CONFIG-iphoneos/$TARGET_NAME.app.dSYM $IPA_DIR
#最后,将app打包为ipa:
/usr/bin/xcrun -sdk iphoneos PackageApplication -v $BUILD_DIR/$BUILD_CONFIG-iphoneos/$APPDISPLAY_NAME.app -o ${WORKSPACE}/ipa/$APPDISPLAY_NAME${BUILD_NUMBER}.ipa
更新svn命令
#更新到svn
svn commit -m "jenkins auto packaging and chang Bundle version to ${BUILD_NUMBER}"
上传到fir命令
export LANG="en_US.UTF-8"
#环境变量的更改
if ${host_distribution}; then
DESCRIPTION="网络环境:正式环境
${fir_description}"
else
DESCRIPTION="网络环境:测试环境
${fir_description}"
fi
#上传到fir
/usr/local/bin/fir publish ${WORKSPACE}/ipa/appName${BUILD_NUMBER}.ipa -T firtoken -c "${DESCRIPTION}"