jenkins configuration
**3 types of packaged builds
app-debug:
Development certificate, dev configuration file, Configuration in the script is set to Debug
app-adhoc
Production certificate, Adhoc configuration file, Configuration in the script is set to Adhoc
app-release
Production certificate, Appstore configuration file, Configuration in the script is set to Release
** Process
-->jenkins selects the corresponding build to package
-->After packaging is completed, send it to Dandelion. Get the QR code and link.
-->After packaging is completed, store the ipa and dysm files in the private server and obtain the corresponding links.
-->DingTalk group notification. Information included: package name, version number, build number, branch name, build environment, Dandelion QR code, Dandelion ipa installation link, ipa file download link, dysm file download link.
Configurations
Three environment configurations
Debug:
1. Open the development package (development certificate, jkdj_dev configuration file).
2. Use #if DEBUG to judge within the project.
3. Certain situations that require development certificates can be tested in this environment, such as testing of development certificate push.
4. The debug panel (currently the private JKDJ_DebugKit library) is added to this environment to enable API environment switching, performance debugging, etc.
Adhoc:
1. Create adhoc package (production certificate, jkdj_Adhoc configuration file)
2. Use #if ADHOC to make judgments in the project.
3. Certain situations that require production certificates can be tested in this environment, such as testing of production certificate push.
4. The debug panel (currently the private JKDJ_DebugKit library) is added to this environment to enable API environment switching, performance debugging, etc.
5. This environment can also be used as a daily test package
Release:
1. Download the Appstore package (production certificate, jkdj_Appstore configuration file).
2. The debug panel is no longer imported into this environment, and the API environment is fixed to the production environment.
3. Only for appstore
API configuration
API_Dev: Development environment API
API_Test: Test environment API
API_Pre: Pre-release environment API
API_Dis: Production environment API
GCC_PREPROCESSOR_DEFINITIONS='$$(inherited) $(ApiEnvironment) '
Project configuration
1. Add a new environment configuration Adhoc in Project
2. Configure the predefined macro ADHOC=1 in this environment in the build Setting directory of Target-HealthManager.
3. podfile imports the debug private library, only in Debug and Adhoc environments
pod 'JKDJ_DebugKit', '2.0', :configurations => ['Debug','Adhoc'] #复星健康debug面板(包含环境切换,性能调试能)Plain Text
4. Macro judgment, example
debug panel
#if (defined(DEBUG) || defined(ADHOC))
[[JKDebugManager shareManager] show];
#else
#endif
api environment
- (NSString *)hostUrl{
#if (defined(DEBUG) || defined(ADHOC))
{
#ifdef API_Dev
return API_Dev_URL; //开发环境
#endif
#ifdef API_Test
return API_Test_URL; //测试环境
#endif
#ifdef API_Pre
return API_Uat_URL; //预发环境
#endif
#ifdef API_Dis
return API_Distribute_URL; //生产环境
#endif
NSUserDefaults * def = [NSUserDefaults standardUserDefaults];
NSString * host = [def objectForKey:NSUserDefault_HostUrl];
if ([NSString isEmpty:host]) {
return API_Distribute_URL; //生产环境
}else if ([host rangeOfString:@"api.health2m"].location != NSNotFound) {
return API_Distribute_URL;
} else{
return host;
}
}
#else
{
return API_Distribute_URL; //生产环境
}
#endif
}
Automated packaging script (currently used)
#复星健康自动化打包脚本
#参数 ARCHIVE_TYPE
#{
# DEVELOPMENT->开发包
# ADHOC->Adhoc包,日常包
# APPSTORE->删除appstore的包
#}
#
#实例 bash JKAutoBuild.sh DEVELOPMENT
function auto() { #构建包
#打包类型
ARCHIVE_TYPE=$1
#编译模式
BUILD_TYPE="Debug"
EXPORT_TYPE="Develop"
if [[ $ARCHIVE_TYPE == "DEVELOPMENT" ]]; then
BUILD_TYPE="Debug"
EXPORT_TYPE="Develop"
elif [[ $ARCHIVE_TYPE == "ADHOC" ]]; then
BUILD_TYPE="Release"
EXPORT_TYPE="Adhoc"
elif [[ $ARCHIVE_TYPE == "APPSTORE" ]]; then
BUILD_TYPE="Release"
EXPORT_TYPE="AppStore"
else
echo "defult"
fi
# 工程名
APP_NAME="HealthManager"
# workspace名
WORK_SPACE="HealthManager.xcworkspace"
#包名(Package)
BUNDLEID==`xcodebuild -showBuildSettings | grep PRODUCT_BUNDLE_IDENTIFIER | tr -d 'PRODUCT_BUNDLE_IDENTIFIER ='`
#info.plist路径
project_infoplist_path="./${APP_NAME}/Info.plist"
#取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${project_infoplist_path}")
#取build值
bundleVersion=`xcodebuild -showBuildSettings | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION ='`
#时间
DATE="$(date +%Y%m%d)"
# IPA路径
IPAPATH="${APP_NAME}_${BUILD_TYPE}_V${bundleShortVersion}_B${bundleVersion}_${DATE}"
# xcarchive
XCARCHIVE="${APP_NAME}_${BUILD_TYPE}_V${bundleShortVersion}_B${bundleVersion}_${DATE}.xcarchive"
#IPA输入路径
IPAPATHOUT="./build/${IPAPATH}/${APP_NAME}.ipa"
#dYSM文件目录
dYSMPATHOUT="./build/${XCARCHIVE}/dSYMs/${APP_NAME}.app.dSYM"
#上传appstore
##账号
parameter_username=""
#独立密码
parameter_password=""
# 开始计时
SECONDS=0
echo "\n\n\033[32m -----------------------Xcode打包-----------------------\033[0m\n\n\n"
# 清理
echo "\n\n\033[32m +++++++++++++++++清理中+++++++++++++++++\033[0m\n\n\n"
xcodebuild -workspace "${WORK_SPACE}" -scheme "${APP_NAME}" -configuration "${BUILD_TYPE}" clean
# 编译
echo "\n\n\033[32m +++++++++++++++++编译中+++++++++++++++++\033[0m\n\n\n"
xcodebuild -workspace "${WORK_SPACE}" -sdk iphoneos -scheme "${APP_NAME}" -archivePath "./build/${XCARCHIVE}" -configuration "${BUILD_TYPE}" archive
# 打包
echo "\n\n\033[32m +++++++++++++++++打包中++++++++++++++++++\033[0m\n\n\n"
xcodebuild -exportArchive -archivePath "./build/${XCARCHIVE}" -exportPath "./build/${IPAPATH}" -exportOptionsPlist "./ExportOptionsPlist/${EXPORT_TYPE}ExportOptionsPlist.plist" -allowProvisioningUpdates
# 验证
if [ -f ${IPAPATHOUT} ] ; then
echo "\n\n\033[32m +++++++++++++++++打包成功,用时 ${SECONDS}s ++++++++++++++++++\033[0m\n\n\n"
else
echo "\n\n\033[32m +++++++++++++++++打包失败++++++++++++++++++\033[0m\n\n\n"
fi
echo "\n\n\033[32m -----------------------上传到蒲公英-----------------------\033[0m\n\n\n"
#蒲公英上的user Key
uKey="4371fb11c6bbccb4c613ae93ded1fef0"
#蒲公英上的API Key
apiKey="789438bcbd5da6f7b5620f0ed143e72f"
#蒲公英版本更新描述,这里取git最后一条提交记录作为描述
MSG=`git log -1 --pretty=%B`
#要上传的ipa文件路径
echo $IPAPATHOUT
# 执行上传至蒲公英的命令
echo "++++++++++++++upload+++++++++++++"
curl -F "file=@${IPAPATHOUT}" -F "uKey=${uKey}" -F "_api_key=${apiKey}" -F "buildUpdateDescription=${MSG}" http://www.pgyer.com/apiv2/app/upload > uploadResponse.json
#cat uploadResponse.json
echo
echo "++++++++++++++提取上传响应信息+++++++++++++"
uploadResult=`cat $WORKSPACE/uploadResponse.json`
url1=`echo "${uploadResult##*"buildQRCodeURL"}"`
urlLength=`expr ${#url1} - 6`
url2=`echo ${url1:3:$urlLength}`
buildQRCodeURL=`echo $url2 | sed 's:\\\/:\/:g'`
if [ ! $buildQRCodeURL ]; then
echo "~~~~~~~~~~~~~~~~~~~上传失败~~~~~~~~~~~~~~~~~~~"
else
echo "~~~~~~~~~~~~~~~~~~~上传成功~~~~~~~~~~~~~~~~~~~"
echo "构建版本:${bundleShortVersion}"
echo "二维码链接:${buildQRCodeURL}"
fi
echo "buildQRCodeURL=${buildQRCodeURL}\r\nbuildVersion=${bundleShortVersion}">> uploadResult.txt
echo "\n\n\033[32m -----------------------上传钉钉群通知-----------------------\033[0m\n\n\n"
curl 'https://oapi.dingtalk.com/robot/send?access_token=48c80fea344d28d6a4c5d2965013a1dd3f54976d01ee39951f39c9b68a4d6f3c' \
-H 'Content-Type: application/json' \
-d "{'msgtype':'markdown','markdown':{'title':'复星健康iOS端','text':'### 复星健康iOS端 \n * 构建分支 => ${Branch_Tag} \n * 构建环境 => ADHOC \n ![screenshot](${buildQRCodeURL}) \n>'}}"
echo "\n\n\033[32m -----------------------上传dSYM文件-----------------------\033[0m\n\n\n"
#只有appstore包才上传bugly
if [[ ${EXPORT_TYPE} == "AppStore" ]]; then
zip -rj "${dYSMPATHOUT}.zip" ${dYSMPATHOUT}
curl -k "https://api.bugly.qq.com/openapi/file/upload/symbol?app_key=0de566a9-f35a-4d29-b9c4-b7fff662ebe0&app_id=a8b0724bed" --form "api_version=1" --form "app_id=a8b0724bed" --form "app_key=0de566a9-f35a-4d29-b9c4-b7fff662ebe0" --form "symbolType=2" --form "bundleId=${BUNDLEID}" --form "productVersion=${bundleShortVersion}" --form "channel=AppStore" --form "fileName=${APP_NAME}.app.dSYM.zip" --form "file=@${dYSMPATHOUT}.zip" --verbose
else
echo "not upload budly"
fi
echo "\n\n\033[32m -----------------------上传AppStore-----------------------\033[0m\n\n\n"
#只有appstore包才上传appstore
if [[ ${EXPORT_TYPE} == "AppStore" ]]; then
#验证账号密码
if [ ${#parameter_username} != 0 -a ${#parameter_username} != 0 ]
then
echo "\n\033[32m****************\n开始上传AppStore\n****************\033[0m\n"
#验证APP
altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
"${altoolPath}" --validate-app \
-f "$IPAPATHOUT" \
-u "$parameter_username" \
-p "$parameter_password" \
--output-format xml
#上传APP
"${altoolPath}" --upload-app \
-f "$IPAPATHOUT" \
-u "$parameter_username" \
-p "$parameter_password" \
--output-format xml
echo "\n\033[32m****************\n上传AppStore完毕\n****************\033[0m\n"
fi
fi
}
auto $1