iOS-Jenkins-SVN一键部署发布

2018-01-10  本文已影响0人  dl_wj15

打包提供给测试还是上传到AppStore都需要进行一系列繁琐的操作,不但耗时还需要各种等待,所以笔者想着通过脚本语言来实现这个繁琐的过程,使用Jenkins来一键部署。

一、Jenkins工具的安装、卸载和启用

安装、卸载

1、安装
安装方式有两种:

本文采用终端方式安装

安装
brew install jenkins
WX20180110-165245.png

安装好的目录


WX20180110-162555@2x.png
2、卸载
brew uninstall jenkins

启动

jenkins

WX20180110-165509.png

3、登录Jenkins
在浏览器上输入http://localhost:8080
下载插件(系统管理->管理插件->可选插件):Xcode integration

WX20180110-173935.png WX20180110-170231.png WX20180110-170309.png WX20180110-170500.png
WX20180110-170525.png WX20180110-171224.png

to-orient/strip%7CimageView2/2/w/1240)

1515575763644.jpg WX20180110-171434.png WX20180110-174932@2x.png WX20180110-174430@2x.png WX20180110-174608@2x.png WX20180110-175332@2x.png

到此jenkins已经部署完毕

二、shell脚本

WX20180110-180137@2x.png
#shell绝对路径
shell_path=$(cd `dirname $0`; pwd)

#凡是在jenkins里添加的参数都可以移除,但有些需要添加默认值
#TargetDir是在jenkins里构建添加的参数
targetDir=${TargetDir}
if [ ! $targetDir ];then
targetDir=${shell_path}
fi
if [ ! -d ${targetDir}/IPADir ];then
mkdir ${targetDir}/IPADir;
fi

#工程绝对路径
project_path=$(pwd)

#工程名 将XXX替换成自己的工程名
project_name=LiwaiU

#scheme名 将XXX替换成自己的sheme名
scheme_name=LiwaiU

#打包模式 Debug/Release
development_mode=Debug

#info.plist文件
project_infoplist_path="${project_path}/${project_name}/info.plist"
#修改build版本号
#BundleVersion是在jenkins里构建添加的参数
if [ $BundleVersion ];then
$(/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${BundleVersion}" "${project_infoplist_path}")
fi

#日期
DATE="`date '+%Y-%m-%d%H-%M-%S'`"

#build文件夹路径
build_path=${targetDir}/IPADir/build

#plist文件所在路径
exportOptionsPlistPath=${shell_path}/exportTest.plist

#导出.ipa文件所在路径
exportIpaPath=${targetDir}/IPADir/${project_name}${DATE}
#默认放置在BuildShell.sh文件的文件夹里
echo 'IPA包存放路径:'${exportIpaPath}

#BundleVersion
#type是在jenkins里构建添加的参数
number=${type}

if [ $number == 1 ];then
development_mode=Release
exportOptionsPlistPath=${shell_path}/exportAppstore.plist
else
development_mode=Debug
exportOptionsPlistPath=${shell_path}/exportTest.plist
fi


echo '///-----------'
echo '/// 正在清理工程'
echo '///-----------'
xcodebuild \
clean -configuration ${development_mode} -quiet  || exit


echo '///--------'
echo '/// 清理完成'
echo '///--------'
echo ''

echo '///-----------'
echo '/// 正在编译工程:'${development_mode}
echo '///-----------'
xcodebuild \
archive -workspace ${project_path}/${project_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${development_mode} \
-archivePath ${build_path}/${project_name}.xcarchive  -quiet  || exit

echo '///--------'
echo '/// 编译完成'
echo '///--------'
echo ''

echo '///----------'
echo '/// 开始ipa打包'
echo '///----------'
xcodebuild -exportArchive -archivePath ${build_path}/${project_name}.xcarchive \
-configuration ${development_mode} \
-exportPath ${exportIpaPath} \
-exportOptionsPlist ${exportOptionsPlistPath} \
-quiet || exit

if [ -e $exportIpaPath/$scheme_name.ipa ]; then
echo '///----------'
echo '/// ipa包已导出'
echo '///----------'
open $exportIpaPath
else
echo '///-------------'
echo '/// ipa包导出失败 '
echo '///-------------'
fi
echo '///------------'
echo '/// 打包ipa完成  '
echo '///-----------='
echo ''

echo '///------------'
echo '/// 删除build文件'
echo '///------------'
rm -rf ${build_path}


if [ $RELEASE == true ];then
echo '///-------------'
echo '/// 开始发布ipa包 '
echo '///-------------'
if [ $number == 1 ];then

#验证并上传到App Store
# 将-u 后面的XXX替换成自己的AppleID的账号,-p后面的XXX替换成自己的密码
altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
"$altoolPath" --validate-app -f ${exportIpaPath}/${scheme_name}.ipa -u XXX -p XXX -t ios --output-format xml
"$altoolPath" --upload-app -f ${exportIpaPath}/${scheme_name}.ipa -u  XXX -p XXX -t ios --output-format xml
else

#上传到Fir
# 将XXX替换成自己的Fir平台的token
fir login -T XXX
fir publish $exportIpaPath/$scheme_name.ipa

fi

fi

exit 0

打包IPA需要用到两个plist文件下载
把下载的文件夹放在你喜欢的地方,在jenkins的构建里调用

WX20180110-183227@2x.png

三、脚本中用到的xcodebuild 命令在参考文件中查看

参考文档:

上一篇下一篇

猜你喜欢

热点阅读