转至:http://www.taobaotest.com/blogs/2334
在之前关于使用Xcode Plugin和Clang scan-build Plugin实现iOS的持续集成的文章中指出这些插件在实现需要的功能时实际上也是借助了命令行来实现,这几天稍稍研究了一下这些命令行,根据捕捉到的命令进行了整理,目前整合出了完全使用命令行来实现iOS的持续集成的方式,目前把相关的命令行代码分享一下,供大家参考:
#设置命令路径
WORKSPACE_PATH=`pwd`
SCAN_BUILD_PATH=~/dev-tools/clang/llvm/tools/clang/tools/scan-build/scan-build
CLANG_PATH=/usr/bin/clang
XCODEBUILD_PATH=/usr/bin/xcodebuild
XCRUN_PATH=/usr/bin/xcrun
#设置用户变量(需要用户进行配置,否则构建会失败)
#静态扫描第三方问题数目
ERROR_COUNT=0
#要打包的Target名称
APP_TARGET=
#单元测试的Test Target名称
#APP_TEST_TARGET=
SIMULATOR_SDK=iphonesimulator6.0
OS_SDK=iphoneos6.0
#输入内测包所需的mobileprovision文件位置
MOBILEPROVISION_PATH=
#输入解锁登录证书的密码
PASSWORD=
cd ${WORKSPACE_PATH}
#执行静态代码扫描
rm -rf scan.output
rm -rf ${WORKSPACE_PATH}/clangScanBuildReports
${SCAN_BUILD_PATH} -k -v -v -o ${WORKSPACE_PATH}/clangScanBuildReports –use-analyzer ${CLANG_PATH} xcodebuild -target ${APP_TARGET} -configuration Debug -sdk ${SIMULATOR_SDK} clean build | tee scan.output
ACC_ERROR_COUNT=`grep -E ‘^scan-build: ([0-9]+) bugs found’ scan.output | awk ‘{print $2}’`
#处理检查结果,如果扫描出的问题数目多于第三方问题总数表示本工程也存在问题,构建失败
if [ ${ACC_ERROR_COUNT} -gt ${ERROR_COUNT} ]; then
echo ”scan-build found ${ACC_ERROR_COUNT} bugs, larger than ${ERROR_COUNT}. Please check…”
exit 1
fi
#自定义脚本(可用于切换环境或者更改签名)
#执行单元测试
#编译测试环境app(可以自行更改sdk参数和configuration参数)
${XCODEBUILD_PATH} -target ${APP_TARGET} -sdk ${SIMULATOR_SDK} -configuration Debug clean build
#自定义脚本(可用于切换环境或者更改签名)
#解锁登录证书链
/usr/bin/security list-keychains -s ${HOME}/Library/Keychains/login.keychain
/usr/bin/security default-keychain -d user -s ${HOME}/Library/Keychains/login.keychain
/usr/bin/security unlock-keychain -p ${PASSWORD} ${HOME}/Library/Keychains/login.keychain
#编译线上环境app(可以自行更改sdk参数和configuration参数)
${XCODEBUILD_PATH} -target ${APP_TARGET} -sdk ${OS_SDK} -configuration Release clean build
#构建ipa包
${XCRUN_PATH} -sdk ${OS_SDK} PackageApplication -v ${WORKSPACE_PATH}/build/Release-iphoneos/${APP_TARGET}.app -o ${WORKSPACE_PATH}/build/Release-iphoneos/${APP_TARGET}-Release-RC.ipa –embed ${MOBILEPROVISION_PATH}
#自定义脚本(svn的还原或者移动安装包位置)
目前在本地生活业务线已经进行了相关的测试,目前验证的结果显示和使用Xcode等插件的效果是一致的;
本文固定链接: http://www.test-life.org/?p=350 | 测试之路-My Test Space