#目标机器IP
REMOTE="192.168.160.96"
#密码
PASSWORD=123456
#工程目录
PROJECT_PATH="/Users/dy/Documents/jenkins_iphone_code/mobile/iOS/iPhone/1.2.1"
#要打包的Target名称
APP_TARGET=bundleName
#单元测试的Test Target名称
APP_TEST_TARGET=ATDD
#模拟器SDK
SIMULATOR_SDK=iphonesimulator6.0
OS_SDK=iphoneos6.0
#签名
IPHONE_CODE_SIGN="iPhone' 'Distribution:' 'companyName' 'Ltd"
#证书路径
MOBILEPROVISION_PATH=/Users/dy/Library/MobileDevice/Provisioning' 'Profiles/**.mobileprovision
#拷贝代码到目的机器
scp -r ${WORKSPACE}/* dy@${REMOTE}:/Users/dy/Documents/jenkins_iphone_code
#等待拷贝
sleep 10
#检测xcodebuild版本
ssh dy@${REMOTE} "xcodebuild -version"
ssh dy@${REMOTE} "xcodebuild -showsdks"
#编译工程文件
ssh dy@${REMOTE} "cd ${PROJECT_PATH}; xcodebuild -target ${APP_TARGET} -sdk ${SIMULATOR_SDK} -configuration Debug clean build"
#编译测试工程文件
ssh dy@${REMOTE} "cd ${PROJECT_PATH}; xcodebuild -target ${APP_TEST_TARGET} -sdk ${SIMULATOR_SDK} -configuration Debug clean build"
#解锁登录证书链
ssh dy@${REMOTE} "/usr/bin/security list-keychains -s /Users/dy/Library/keychains/login.keychain"
ssh dy@${REMOTE} "/usr/bin/security default-keychain -d user -s /Users/dy/Library/keychains/login.keychain"
ssh dy@${REMOTE} "/usr/bin/security unlock-keychain -p ${PASSWORD} /Users/dy/Library/keychains/login.keychain"
ssh dy@${REMOTE} "/usr/bin/security unlock-keychain -p ${PASSWORD}"
#构建ipa包
ssh dy@${REMOTE} "cd ${PROJECT_PATH}; xcodebuild -target ${APP_TARGET} -sdk ${OS_SDK} -configuration CODE_SIGN_IDENTITY=${IPHONE_CODE_SIGN} Release clean build"
ssh dy@${REMOTE} "cd ${PROJECT_PATH}; xcrun -sdk ${OS_SDK} PackageApplication -v ${PROJECT_PATH}/build/Release-iphoneos/Funshion.app -o ${PROJECT_PATH}/build/Release-iphoneos/**.ipa --sign "${IPHONE_CODE_SIGN}" --embed ${MOBILEPROVISION_PATH}"
#启动模拟器运行funshion.app
ssh dy@${REMOTE} "/Users/dy/Documents/iphonesim launch ${PROJECT_PATH}/build/build/Debug-iphonesimulator/Funshion.app“
#运行单元测试
ssh dy@${REMOTE} "cd ${PROJECT_PATH}; xcodebuild -target ${APP_TEST_TARGET} -sdk ${SIMULATOR_SDK} -configuration Debug clean build"
#静态检测
SCAN_BUILD_PATH=/Users/wenbo/Documents/scan_build/scan-build
#静态扫描第三方问题数目
ERROR_COUNT=30
#清除上一次记录
ssh dy@${REMOTE} "rm -rf scan.output"
ssh dy@${REMOTE} "rm -rf ${PROJECT_PATH}/scanBuildReports"
ssh dy@${REMOTE} "cd ${PROJECT_PATH};${SCAN_BUILD_PATH} -k -v -v -o ${PROJECT_PATH}/scanBuildReports xcodebuild -target ${APP_TARGET} -sdk ${SIMULATOR_SDK} -configuration Debug clean build | tee scan.output"
ssh dy@${REMOTE} "ACC_ERROR_COUNT=`grep -E '^scan-build: ([0-9]+) bugs found' scan.output | awk '{print $2}'`"
#处理检查结果
ssh dy@${REMOTE} "echo "scan-build found ${ACC_ERROR_COUNT} bugs."