赞
踩
之前打包都是用Xcode直接打包的,很久之前也用过Fastline。
最近接到一个这样的需求:在Jenkins上创建一个任务,可以配置App Name 、AccessKey、SecretKey和不同的Bundle ID,这些完全由QA自己填,方便生成不同的商户和测试功能。
由于之前在Jenkins上有打包的代码(之前的只能选择Build Type),所以只需要把原来的修改一下,把遇到的问题都记录下来,防止以后再出错。
- #!/bin/bash
- #这些是配置参数
- TENANTNAME=${TENANT_NAME}
- APPNAME=${APP_NAME}
- ACCESSKEY=${ACCESS_KEY}
- SECRETKEY=${SECRET_KEY}
- BUILDTYPE=${BUILD_TYPE}
- BUNDLEID=${BUNDLE_ID}
- PROVISIONINGPROFILE=${PROVISIONING_PROFILE}
-
- # test cmd result
- IF_BUILD_FAILED()
- {
- if [[ $1 -ne 0 ]]; then
- echo "$2"
- exit 1
- fi
- }
-
- # replace string in specil path
- REPLACE_STRING_IN_FILE()
- {
- SOURCE=$1
- TARGET=$2
- FILE=$3
- OS=`uname`
- if [[ ${OS} == "Darwin" ]]; then
- sed -i "" "s/${SOURCE}/${TARGET}/g" ${FILE}
- PRINTF "if"
- else
- PRINTF "else"
- sed -i "s/${SOURCE}/${TARGET}/g" ${FILE}
- fi
- }
-
- packaging()
- {
-
- #***********配置项目
- #工程名称(Project的名字)
- MWProjectName=$1
- #scheme名字 -可以点击Product->Scheme->Manager Schemes...查看
- MWScheme=$2
- #Release还是Debug
- MWConfiguration=$3
- #日期
- MWDate=`date +%Y%m%d_%H%M`
- #工程路径
- MWWorkspace=$4
- #build路径
- MWBuildDir=$5
- #plist文件名,默认放在工程文件路径的位置
- MBPlistName=$6
-
- #创建构建和输出的路径
- mkdir -p $MWBuildDir
-
- #构建
- xcodebuild archive \
- -workspace "$MWProjectName.xcworkspace" \
- -scheme "$MWScheme" \
- -configuration "$MWConfiguration" \
- -archivePath "$MWBuildDir/$MWProjectName" \
- clean \
- #build \
- # -derivedDataPath "$MWBuildTempDir"
-
- # 生成ipa
- xcodebuild -exportArchive \
- -archivePath "$MWBuildDir/$MWProjectName.xcarchive" \
- -exportPath "$MWBuildDir/$MWProjectName" \
- -exportOptionsPlist "$MWWorkspace/$MBPlistName" \
- -allowProvisioningUpdates YES #这里是关键,因为使用了Automatically manage signing 这个必填,上一行的\一定不要忘记,这个问题找了好久
- open $MWBuildDir
-
- }
-
- cd ${SOURCECODEDIR}
- #replace app name 替换AppName
- echo "Replace app name..."
- SOURCE_STR=${APPNAME}
- PLIST_PATH="SchoolApp/Info.plist"
- plutil -replace CFBundleDisplayName -string "${SOURCE_STR}" ${PLIST_PATH}
- IF_BUILD_FAILED $? "Replace app name failed!"
-
-
- #replace Bundle ID
- echo "Replace Bundle ID..."
- cd SchoolApp.xcodeproj
- #这个遇到了一个问题,必须使用双引号,使用单引号的话不会转换,也是对语言不熟悉造成的
- sed -i '' "s/${Old_BundleID}/${New_BundleID}/g" project.pbxproj
- cd ../
- IF_BUILD_FAILED $? "Replace Bundle ID failed!"
-
- #replace url
- echo "Replace url..."
- SOURCE_STR="nlxx"
- REPLACE_STRING_IN_FILE ${SOURCE_STR} ${TENANTNAME} ${TARGET_URL_FILE}
- IF_BUILD_FAILED $? "Replace url failed!"
-
- # replace accesskey
- echo "Replace accesskey..."
-
- str=${ACCESS_KEY}
- ACCESSKEYARR=(${str//#/ })
- if [[ ${BUILDTYPE} == "Debug" ]]; then
- ACCESSKEY=${ACCESSKEYARR[0]}
- SOURCE_STR=${OLDKEY}
- REPLACE_STRING_IN_FILE ${SOURCE_STR} ${ACCESSKEY} ${TARGET_KEY_FILE}
- IF_BUILD_FAILED $? "Replace debug accesskey failed!"
- else
- ACCESSKEY=${ACCESSKEYARR[1]}
- SOURCE_STR=${OLDKEY}
- REPLACE_STRING_IN_FILE ${SOURCE_STR} ${ACCESSKEY} ${TARGET_KEY_FILE}
- IF_BUILD_FAILED $? "Replace release accesskey failed!"
- fi
-
- # replace secretkey
- echo "Replace secretkey..."
-
- SECRET_KEY_STR=${SECRET_KEY}
- SECRET_KEY_ARR=(${SECRET_KEY_STR//#/ })
-
- if [[ ${BUILDTYPE} == "Debug" ]]; then
- SECRETKEY=${SECRET_KEY_ARR[0]}
- SOURCE_STR="${OLDKEY}
- REPLACE_STRING_IN_FILE ${SOURCE_STR} ${SECRETKEY} ${TARGET_KEY_FILE}
- IF_BUILD_FAILED $? "Replace debug secretkey failed!"
- else
- SECRETKEY=${SECRET_KEY_ARR[1]}
- SOURCE_STR="${OLDKEY}
- REPLACE_STRING_IN_FILE ${SOURCE_STR} ${SECRETKEY} ${TARGET_KEY_FILE}
- IF_BUILD_FAILED $? "Replace release secretkey failed!"
- fi
-
-
- #函数调用
- # $1 工程名 $2 scheme名字 $3 Release还是Debug $4 工程路径 $5 ipa文件输出路径 $6 plist文件名字
- echo "==============="
- echo ""
- echo ${BUILDTYPE}
- packaging "SchoolApp" "SchoolApp" ${BUILDTYPE} "./" "/Users/jackie/jenkinsArchive/build/buffet" "adhocExportOptions.plist"
- echo ""
- echo "==============="
-
-
-
最后adhocExportOptions.plist文件其实不需要修改什么,provisioningProfiles后面是空的也可以。
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
- <plist version="1.0">
- <dict>
- <key>provisioningProfiles</key>
- <dict>
- <!-- <key>com.****.MHYCXX</key>
- <string>****_AdHoc</string> -->
- </dict>
- <key>compileBitcode</key>
- <false/>
- <key>method</key>
- <string>ad-hoc</string>
- </dict>
- </plist>
因为设置了自动管理签名,所以只需要修改Bundle ID就可以,Provisioning Profile可以不用填
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。