The company has a CI platform, but because the installation package generated on CI is using enterprise certificate, some of the certificate-related functions can not be tested (push, Micro-blog SDK, etc.), so often need to manually generate a Develoment installation package, it is really a little trouble. After a few hours of tinker with Jenkins, I realized that it was possible to build a simple version of the automated integration tool with a little knowledge of the simplest command line.

Without further ado, let’s see how to do it!

1. Use xcodeBuild archive and export ipA package

First, you need to change the Xcode configuration to Auto CoDesign. Check the check box in the red box in the upper and lower pictures. Then Xcode will automatically configure the corresponding certificate and description file according to your configuration parameter.

Archive command:

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

Export ipa command:

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

-exportOptionsPlist Requires an XML configuration file in the following format:

<? xml version="1.0" encoding="UTF-8"? > <! DOCTYPE plist PUBLIC"- / / / / DTD PLIST Apple 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>

Copy the code

The teamID available at https://developer.apple.com/account/#/membership.

2. Upload IPA package using dandelion account

curl -F "file=@bin/projectname.ipa" \
-F "uKey=xxxxxxxxxxx" \
-F "_api_key=xxxxxxxxxxx" \
https://www.pgyer.com/apiv1/app/upload
Copy the code

UKey and _API_key can be found in your dandelion account configuration without further details.

Create a branch and update the code to avoid tainting the xcode. If you want to checkout the xcode, you will have to change the xcode configuration manually. If you want to checkout the xcode, you will have to check it out again.

Git checkout pushTest git merge develop --no-commit git commit -m'pushtest merge'
git push
pod update

Copy the code

###END

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
Copy the code

As if it were a bit crude, we could split the script by function and add a conditional: update.sh:

Git checkout pushTest git merge develop --no-commit git commit -m'pushtest merge'
git push
pod update

Copy the code

upload.sh:

curl -F "file=@bin/projectname.ipa" \
-F "uKey=xxxxxxxxxxx" \
-F "_api_key=xxxxxxxxxxx" \
https://www.pgyer.com/apiv1/app/upload
Copy the code

packg.sh:

cd /Users/admin/Desktop/workspace/projectname

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

fi
fi
fi

Copy the code

Finally, use alias to customize the script into commands

cp packg.sh ~/
vim ~/.bashrc
Copy the code

Add the following command:

alias buildpush='sh ~/packg.sh'
Copy the code

perform

source ~/.bashrc
Copy the code

Then open ~/.bash_profile and add a line:

source ~/.bashrc
Copy the code

Make the alias permanent. Once you’re done and ready to pack, all you need to do is open the terminal and run buildPush.