XCode8 下最简单的自动集成打包脚本

公司已经有一个CI平台,但是由于CI上生成的安装包是用企业证书,有一些和证书相关的功能无法测试(push,微博sdk等),所以经常需要手动生成一个develoment的安装包,实在是有点麻烦。捣鼓了几个小时,发现其实不需要配置复杂的jenkins,了解一点最简单的命令行,就能打造出一个简易版的自动集成工具。

话不多说,来看看到底怎么做吧!

###1.使用 xcodebuild archive并export出ipa包

首先需要将Xcode配置改成auto codesign,勾上下图红框中的勾,这样xcode会自动根据你的configuration参数去配置对应的证书和描述文件。

archive命令:

xcodebuild -workspace projectname.xcworkspace -scheme schemename -configuration Debug -derivedDataPath DerivedData -archivePath "bin/projectname.xcarchive"  -destination generic/platform=iOS  clean archive
复制代码

export ipa命令:

xcodebuild -exportArchive -exportOptionsPlist ./exportPlist.plist -archivePath "bin/projectname.xcarchive" -exportPath "bin/"
复制代码

-exportOptionsPlist这个参数需要有一个xml的配置文件,文件格式如下:

<?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>teamID</key>
	<string>xxxxxxxxxx</string>
	<key>method</key>
	<string>development</string>
	<key>uploadSymbols</key>
	<false/>
</dict>
</plist>

复制代码

其中teamID可以在 https://developer.apple.com/account/#/membership 查到。

###2.使用蒲公英账号上传ipa包

curl -F "file=@bin/projectname.ipa" \
-F "uKey=xxxxxxxxxxx" \
-F "_api_key=xxxxxxxxxxx" \
https://www.pgyer.com/apiv1/app/upload
复制代码

uKey_api_key在你的蒲公英账号配置中能找到,具体不赘述。

###3.创建分支更新代码,避免污染开发分支 完成了上面两步,每次还是得手动去将xcode配置修改,在打完包后还原,还是很不方便,可以将工程代码重新checkout一份,并创建一个新的分支,在分支上进行打包执行打包操作:

git checkout 开发分支名
git pull
git checkout pushTest
git merge develop --no-commit
git commit -m 'pushtest merge'
git push
pod update

复制代码

###END 最后整个脚本如下:

git checkout 开发分支名
git pull
git checkout pushTest
git merge develop --no-commit
git commit -m 'pushtest merge'
git push
pod update

xcodebuild -workspace projectname.xcworkspace -scheme schemename -configuration Debug -derivedDataPath DerivedData -archivePath "bin/projectname.xcarchive"  -destination generic/platform=iOS  clean archive

xcodebuild -exportArchive -exportOptionsPlist ./exportPlist.plist -archivePath "bin/projectname.xcarchive" -exportPath "bin/"

curl -F "file=@bin/projectname.ipa" \
-F "uKey=xxxxxxxxxxx" \
-F "_api_key=xxxxxxxxxxx" \
https://www.pgyer.com/apiv1/app/upload
复制代码

好像有点简陋,我们可以将脚本按功能拆分开来,并加上条件判断: update.sh:

git checkout 开发分支名
git pull
git checkout pushTest
git merge develop --no-commit
git commit -m 'pushtest merge'
git push
pod update

复制代码

upload.sh:

curl -F "file=@bin/projectname.ipa" \
-F "uKey=xxxxxxxxxxx" \
-F "_api_key=xxxxxxxxxxx" \
https://www.pgyer.com/apiv1/app/upload
复制代码

packg.sh:

cd /Users/admin/Desktop/workspace/projectname

sh update.sh
if [ $? -eq 0 ]; then
xcodebuild -workspace SnobMass.xcworkspace -scheme SnobMass -configuration Debug -derivedDataPath DerivedData -archivePath "bin/SnobMass.xcarchive"  -destination generic/platform=iOS  clean archive
if [ $? -eq 0 ]; then
xcodebuild -exportArchive -exportOptionsPlist ./exportPlist.plist -archivePath "bin/SnobMass.xcarchive" -exportPath "bin/"
if [ $? -eq 0 ]; then
sh upload.sh

fi
fi
fi

复制代码

最后利用alias将脚本定制为命令

cp packg.sh ~/
vim ~/.bashrc
复制代码

加入下面的命令:

alias buildpush='sh ~/packg.sh'
复制代码

执行

source ~/.bashrc
复制代码

然后打开~/.bash_profile 在里面加入一行:

source ~/.bashrc
复制代码

让alias永久生效。 大功告成,之后再打包,就只需要打开终端,执行buildpush这个命令就行了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值