jenkins构建打包脚本

参考博客:https://wangjianjun0730.github.io/2017/10/Jenkins/

#!/bin/sh -
export LANG=en_US.UTF-8

# 工程名(根据项目自行填写)
APP_NAME="ybej"

# TARGET名称(根据项目自行填写)
TARGET_NAME="ybej"

# 工程根目录#工程源码目录(这里的${WORKSPACE}是jenkins的内置变量表示(jenkins job的路径):/Users/pingankeji/.jenkins/workspace/Mydemos/)   
# ${WORKSPACE}/MyDemos/ 中的MyDemos根据你的项目自行修改
CODE_PATH="${WORKSPACE}"

# 证书
# 证书配置根据自己的项目自行修改
CODE_SIGN_DISTRIBUTION="iPhone Distribution: Zhongshun Yijia international factoring business (Tianjin) Co., Ltd. (F6U8GB65T3)"

# 存放ipa的文件夹名称(根据自己的喜好自行修改)
IPA_DIR_NAME="${TARGET_NAME}_IPA"

# 导出ipa包的路径
IPA_EXPORT_PATH=${CODE_PATH}${IPA_DIR_NAME}

# 导包方式(这里需要根据需要手动配置:AdHoc/AppStore/Enterprise/Development)
EXPORT_METHOD="${EXPORT_TYPE}"

# 导包方式配置文件路径(这里需要手动创建对应的XXXExportOptionsPlist.plist文件,并将文件复制到根目录下[我这里在源项目的根目录下又新建了ExportPlist文件夹专门放ExportPlist文件])
if test "$EXPORT_METHOD" = "AdHoc"; then
    EXPORT_METHOD_PLIST_PATH=${CODE_PATH}/ExportPlist/AdHocExportOptions.plist
    Configuration_Type="Release"
    
elif test "$EXPORT_METHOD" = "AppStore"; then
    EXPORT_METHOD_PLIST_PATH=${CODE_PATH}/ExportPlist/AppStoreExportOptios.plist
    Configuration_Type="Release"

elif test "$EXPORT_METHOD" = "Enterprise"; then
    EXPORT_METHOD_PLIST_PATH=${CODE_PATH}/ExportPlist/EnterpriseExportOptions.plist
    Configuration_Type="Release"

else 
    EXPORT_METHOD_PLIST_PATH=${CODE_PATH}/ExportPlist/DevelopmentExportOptions.plist
    Configuration_Type="Debug"

fi  

# 指ipa定输出文件夹,如果有删除后再创建,如果没有就直接创建
if test -d ${IPA_EXPORT_PATH}; then
    rm -rf ${IPA_EXPORT_PATH}
    mkdir -pv ${IPA_EXPORT_PATH}
    echo ${IPA_EXPORT_PATH}
else
    mkdir -pv ${IPA_EXPORT_PATH}
fi

# 删除工程文件
echo "+++++++++删除工程文件+++++++++"
rm -rf "${TARGET_NAME}.xcarchive"



echo "++++++++++++++change build ++++++++++++++"

cd "${CODE_PATH}/ybej"
buildPlist="Info.plist"
last_build_version=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${buildPlist})
#这个获取现在的 月日时分 用它来做build号
buildNumber=${last_build_version}$(date +"%d%H%M")
#修改plist文件需要/usr/libexec/PlistBuddy -c命令,CFBundleVersion是修改的这个build号,$buildNumber是你要修改的数值,$buildPlist是你修改哪个地方的plist文件。
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${buildNumber}" "${buildPlist}"

# 进入工程源码根目录
cd "${CODE_PATH}"

echo "++++++++++++++CODE_PATH ${CODE_PATH} ++++++++++++++"

# 更新pod
#/user/local/bin/pod update —verbose —no-repo-update

# 清除工程
echo "++++++++++++++clear++++++++++++++"
xcodebuild -workspace "${APP_NAME}.xcworkspace" -scheme "${TARGET_NAME}" -configuration 'Release' clean

# 获取钥匙串权限(-p 后面的密码为你的开机密码)
/user/bin/security unlock-keychain -p "package" ~/Library/Keychains/login.keychain-db

#将app打包成xcarchive格式文件(PROVISIONING_PROFILE后面是你配置的证书对应的描述文件UUID)
echo "+++++++++++++++++archive+++++++++++++++++"
xcodebuild  archive -workspace "${APP_NAME}.xcworkspace" -scheme "${TARGET_NAME}" -archivePath "${TARGET_NAME}.xcarchive" -configuration "${Configuration_Type}" 
# 将xcarchive格式文件打包成ipa
echo "+++++++++++++++++ipa+++++++++++++++++"
xcodebuild -exportArchive -archivePath "${APP_NAME}.xcarchive" -exportPath "${IPA_EXPORT_PATH}" -exportOptionsPlist ${EXPORT_METHOD_PLIST_PATH}


echo "+++++++++++++++++final operation +++++++++++++++++"

if test "$Configuration_Type" = "Release"; then

    deliver -u [email protected] -a com.ybejia.ybej --ipa ${IPA_EXPORT_PATH}/${APP_NAME}.ipa --skip_screenshots -f --skip_metadata

else 
# 登录fir,此处将APIToken换成自己申请的APIToken(-T 后面是你的fir账号APIToken)
fir login -T 356458773d7cf28bbc693d3f29b5c762
# 发布到fir
fir publish ${IPA_EXPORT_PATH}/${APP_NAME}.ipa
fi

你可能感兴趣的:(jenkins构建打包脚本)