下图是搭建Jenkins的流程图,网上教程很多这里就不赘述了
主要作为学习笔记记录下shell脚本
#bin/bsah - l
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# 进入工程文件目录
cd /Users//Desktop/Demo
# 提交本地更改
git add .
git commit -m "打包更改包版本号"
git pull
git push
# 切换到develop分支
git checkout develop
git branch
# 拉取最新代码
git pull
/usr/local/bin/pod install --verbose --no-repo-update
# 工程名
scheme_name="DemoApp"
# 文件名前缀
APP_NAME="Demo"
# info.plist路径
project_infoplist_path="${scheme_name}/Other/Info.plist"
#指定输出路径
export_path=/Library/WebServer/Documents/ota/Demo/develop
#指定 ExportOptionsPlist文件路径
ExportOptionsPlist_path=/Library/WebServer/Documents/ota/DemoApp
#取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${project_infoplist_path}")
echo "========= $bundleShortVersion ========"
bundleShortVersion=$(($bundleShortVersion + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $bundleShortVersion" "${project_infoplist_path}"
echo "========= $bundleShortVersion ========"
# 指定要打包编译的方式 : Release,Debug,AdHoc...
# 此处循环一次性打Release,Debug,AdHoc三个包 循环体是do - done 之间的代码
for build_configuration in Debug AdHoc Release
do
echo "**********build_configuration: $build_configuration"
# 指定输出ipa路径
export_ipa_path="${export_path}/${build_configuration}"
echo "*********输出的ipa路径: ${export_ipa_path}"
# 指定输出归档文件地址
export_archive_path="$export_path/${build_configuration}/$scheme_name.xcarchive"
echo "*********输出的归档文件路径: ${export_archive_path}"
# manifest.plist的文件路径
mainfestPlistPath="/Library/WebServer/Documents/ota/MMCApp/develop/manifest/manifest_${build_configuration}_${bundleShortVersion}_mmc.plist"
echo "*********manifest.plist的文件路径:${mainfestPlistPath}"
cat << EOF > ${mainfestPlistPath}
<?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>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string></string>
</dict>
<dict>
<key>kind</key>
<string>display-image</string>
<key>url</key>
<string></string>
</dict>
<dict>
<key>kind</key>
<string>full-size-image</string>
<key>url</key>
<string></string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>com.ucarinc.mmcapp</string>
<key>bundle-version</key>
<string>2.0.0</string>
<key>kind</key>
<string>software</string>
<key>title</key>
<string>MMCApp</string>
</dict>
</dict>
</array>
</dict>
</plist>
EOF
#ipa下载地址
ipa_download_path="https://10.99.33.133/ota/$scheme_name/develop/${build_configuration}"
# 导出ipa所需要的plist文件路径
if [ "$build_configuration" = "AdHoc" ] ; then
ExportOptionsPlistPath="$ExportOptionsPlist_path/AdHocExportOptionsPlist.plist"
elif [ "$build_configuration" = "Release" ] ; then
ExportOptionsPlistPath="$ExportOptionsPlist_path/AppStoreExportOptionsPlist.plist"
elif [ "$build_configuration" = "Debug" ] ; then
ExportOptionsPlistPath="$ExportOptionsPlist_path/DevelopmentExportOptionsPlist.plist"
fi
# 指定输出ipa名称 : scheme_name + bundleShortVersion
DATE="$(date +%Y%m%d%H-%M-%S)"
ipa_name="${scheme_name}_V${bundleShortVersion}_${DATE}.ipa"
#下面2行是集成有Cocopods的用法
echo "=================clean================="
# xcodebuild -workspace "${scheme_name}.xcworkspace" -scheme "${scheme_name}" -configuration ${build_configuration} clean
echo "+++++++++++++++++build+++++++++++++++++"
xcodebuild -workspace "${scheme_name}.xcworkspace" -scheme "${scheme_name}" -sdk iphoneos -configuration ${build_configuration} SYMROOT='$(PWD)'
xcodebuild clean -workspace ${scheme_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration}
xcodebuild archive -workspace ${scheme_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration} \
-archivePath ${export_archive_path}
xcodebuild -exportArchive \
-archivePath ${export_archive_path} \
-exportPath ${export_ipa_path} \
-exportOptionsPlist ${ExportOptionsPlistPath}
# 修改ipa文件名称
mv $export_ipa_path/$scheme_name.ipa $export_ipa_path/$ipa_name
# 获取IPA下载链接
ipa_download_url=$(/usr/libexec/PlistBuddy -c "print items:0:assets:0:url" "${mainfestPlistPath}")
ipa_download_url=$"$ipa_download_path/$ipa_name"
echo "********ipa下载链接: $ipa_download_url ========"
# 更改 plist 文件中的下载地址
/usr/libexec/PlistBuddy -c "Set :items:0:assets:0:url $ipa_download_url" "${mainfestPlistPath}"
done
macOS 自带apache服务,终端输入 sudo apachectl start ,浏览器输入http://127.0.0.1,如果出现It Works!,OK,服务器启动成功。然后生成ssl证书,配置apache
站点目录 /Library/WebServer/Documents/ 打出的包放到该目录下 ,其他人可以通过访问你的IP去下载安装包
安装的时候注意:
手机跟电脑在同一个局域网内,手机访问服务器的页面,先点击安装SSL证书,安装证
书,然后在设置一>通用一 > 描述文件,设置刚才安装的证书为信任。接下来最重
要的一步,设置一>通用一 > 关于本机,最下面的证书信任设置,再次设置信任。
这个时候再返回网页才能下载安装app。否则会出现"无法连接**".测试没有问题,进
行下一步。