ios,jenkins,参数化构建,shell,xcodebui
1.参数化构建,ios需要两个版本,一个是企业版内部测试,一个是appstore版本,如下图所示,打钩参数化构建,添加Boolean Value的参数,名称设置为IS_INHOUSE_VERSION。这样在execute shell中构建的时候可以这样写:
if [ true == $IS_INHOUSE_VERSION ]; then
echo "archive inhouse version"
else
echo "archive appstore version"
fi
2.版本号同步,修改程序的小版本号Build版本号,就是在xcodebuild前,修改plist文件,使用PlistBuddy。
#修改ipa的版本号,和jenkins编译的号码相同
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "${WORKSPACE}/info.plist"
3.xcodebuild
/usr/bin/xcodebuild -scheme buspaipai -workspace helloworld.xcworkspace -configuration Release clean build
/usr/bin/xcrun -sdk iphoneos PackageApplication -v ~/Library/Developer/Xcode/DerivedData/helloworld-guftoidjqmsbfvajothheubre***/Build/Products/Release-iphoneos/helloworld.app -o ${WORKSPACE}/Build/helloworld-appstore.ipa
4.多bundle identifier,不同版本主要有2个地方的设置,一个是bundle identifier,另外一个是签名。
4.1. bundle identifier,对于xode7(6是不行的),build setting->packaging中,可以设置不同的bundle identifier,截图如下,不过注意如果在general里面设置后,这里又变成统一的了。
4.2. code signing,build setting->code signing直接设置,注意设置id和profile.
5.所有的shell代码如下:
exportLANG=en_US.UTF-8
#pod install --verbose --no-repo-update
/usr/bin/xcodebuild -version
/usr/bin/xcodebuild -showsdks
/usr/bin/xcodebuild -list -workspace helloworld.xcworkspace
#修改ipa的版本号,和jenkins编译的号码相同
/usr/libexec/PlistBuddy -c"Set :CFBundleVersion $BUILD_NUMBER""${WORKSPACE}/helloworld.plist"
#读取程序大版本号,文件名上显示
helloworldMainVersion=$(/usr/libexec/PlistBuddy -c"Print :CFBundleShortVersionString""${WORKSPACE}/helloworld.plist")
security unlock-keychain -p "123456" "~/Library/Keychains/login.keychain"
if[true== $IS_INHOUSE_VERSION ]; then
echo"archive inhouse version"
/usr/bin/xcodebuild -scheme helloworld -workspace helloworld.xcworkspace -configuration adhoc clean build
/usr/bin/xcrun -sdk iphoneos PackageApplication -v ~/Library/Developer/Xcode/DerivedData/helloworld-guftoidjqmsbfvajothheubreqzu/Build/Products/adhoc-iphoneos/helloworld.app -o ${WORKSPACE}/Build/helloworld_V${helloworldMainVersion}_B$BUILD_NUMBER_inhouse.ipa
else
echo"archive appstore version"
/usr/bin/xcodebuild -scheme helloworld -workspace helloworld.xcworkspace -configuration Release clean build
/usr/bin/xcrun -sdk iphoneos PackageApplication -v ~/Library/Developer/Xcode/DerivedData/helloworld-guftoidjqmsbfvajothheubreqzu/Build/Products/Release-iphoneos/helloworld.app -o ${WORKSPACE}/Build/helloworld_V${helloworldMainVersion}_B$BUILD_NUMBER_appstore.ipa
fi
6.最后有点遗憾的是路径名如何简写呢,或者如何设置呢?我写的那个有点恶心。~/Library/Developer/Xcode/DerivedData/helloworld-guftoidjqmsbfvajothheubreqzu/Build/Products/Release-iphoneos/
--------------------------------持续更新中-------------------------
7.换了个jenkins服务器,编译中发现了如下错误:
/usr/bin/codesign --force --sign ..... .app: User interaction is not allowed.
但是不管是命令行方式还是直接用xcode都能编译通过。最后的解决办法是,在/usr/bin/xcodebuild之前加了一句security unlock-keychain -p "password" "~/Library/Keychains/login.keychain".然后编译通过,通过后就可以把这句话给删除了,以后编译都没有问题了。具体可以参考
http://www.verydemo.com/demo_c134_i6629.html
。