Add daily Build to iOS project
Objective
Daily Build is a very meaningful thing and a practice for "continuous integration" in agile development. Daily Build has the following benefits for development:
- Ensures that the code for each check in is available without causing the entire project compilation to fail.
- Progress follow up. The product Manager can see the latest development progress every day, and try out the product to adjust some details. A lot of times, a new feature, you really use a bit to have experience good or bad, so daily build also give the product manager more time to recuperate his design.
- Requirements confirmation. The Product manager can confirm that the feature details of the development are his expectations. Because our development is relatively compact, there are no traditional requirements documentation, so daily build also gives the product manager the ability to confirm the details of the development as early as he expects, and I met a product manager who found that a feature detail was developed that was inconsistent with his expectations, but because of the daily build , allowing me to make changes as early as possible, reducing the cost of the changes.
- Test follow up. If the function point is independent, the test colleague can perform some early tests based on the daily build. The earlier bug feedback can make it less time to modify the bug.
Step xcodebuild Command
How to do daily build? In fact, Xcode provides command line build command, this command is Xcodebuild, with Xcodebuild-usage
You can view all of the available parameters as follows:
[Tangqiao ~]$xcodebuild-usage Usage:xcodebuild [-project <projectname>] [[-target <targetname>]...| -alltargets] [-configuration <configurationname>] [-arch <architecture>] ... [-SDK [<sdkname>|<sdkpath>]] [<buildsetting>=<value>] ... [<buildaction>] ... Xcodebuild [-project <projectname>]-scheme <schemeName> [-configuration <configurationname>] [- Arch <architecture> [-SDK [<sdkname>|<sdkpath>]] [<buildsetting>=<value>] ... [<buildaction>] ... Xcodebuild-workspace <workspacename>-scheme <schemeName> [-configuration <configurationname>] [- Arch <architecture> [-SDK [<sdkname>|<sdkpath>]] [<buildsetting>=<value>] ... [<buildaction>] ... xcodebuild-version [-SDK [<sdkfullpath>|<sdkname>] [<infoitem>] xcodebuild-list [[-project <projectname>]|[ -workspace <workspacename>]] Xcodebuild-showsdks
|
Commands in general are used as follows:
But in daily build, using Release as a configuration is not particularly good. Because the Release certificate may be modified frequently. We can build a configuration specifically for the daily build based on the configuation of Release. In the Project details page, select the Info column, click the "+" sign below the configurations column and select "Duplicate Release Configuration" to create a new Configu named "Dailybuild" Ration, as shown in:
You can then use the following command to do the daily build.
After executing the command, a file named: Yourproduct.app is generated under the build/dailybuild-iphoneos/directory under the current project. This is the program file after the success of our Build.
Generate an IPA file
Next we need to generate an IPA file, in the event of generating an IPA file, Xcode does not seem to provide any tools, but this has no effect, because the IPA file is actually a zip file, we use the system's ZIP command to generate an IPA file. Note that the IPA file does not simply make the edited app file into a zip file, it needs to put the app file in a folder named Payload, and then package the entire Payload directory into an. ipa file, with the following command:
$BUILD _path Mkdir-p Ipa/payload Cp-r./dailybuild-iphoneos/$PRODUCT _name./ipa/payload/ CD IPA $FILE _name *
|
Build the installation file
Apple allows the application to be installed directly on the IPHONE/IPAD using the Itms-services protocol, and we can directly generate the relevant files required for the protocol so that the product manager and test classmates can install the new version of the application directly on the device. Related references can be found here: here and here.
Specifically, it is necessary to generate an HTML file with a link to the Itms-services protocol, as well as a plist file.
The sample code for generating HTML is as follows:
Cat << EOF > install.html <! DOCTYPE Html>, "Content-type" Content= "text/html; Charset=utf-8 "/> <title> install this software </title> <body>, <li> install this software: <a href= "itms-services://?action=download-manifest&url=http%3a%2f% 2fwww.yourdomain.com%2fynote.plist "> $FILE _name</a></li> </ul>, </body> eof |
The code to generate the Plist file is as follows, note that you need to replace the following www.yourdomain.com with the address of your online server, replacing ProductName with your app's installed name.
Cat << EOF > Ynote.plist <?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>http://www.yourdomain.com/$FILE _name</string> </dict> <dict> <key>kind</key> <string>display-image</string> <key>needs-shine</key> <True/> <key>url</key> <string>http://www.yourdomain.com/icon.png</string> </dict> <dict> <key>kind</key> <string>full-size-image</string> <key>needs-shine</key> <True/> <key>url</key> <string>http://www.yourdomain.com/icon.png</string> </dict> </array><key>metadata</key> <dict> <key>bundle-identifier</key> <string>com.yourdomain.productname</string> <key>bundle-version</key> <string>1.0. 0</string> <key>kind</key> <string>software</string> <key>subtitle</key> <string>ProductName</string> <key>title</key> <string>ProductName</string> </dict> </dict> </array> </dict> </plist>
Eof
|
Timed operation
This is very simple and can be done using the CRONTAB-E command. You can feel free to Google a crontab command, you can find a lot of related documents. If we were to execute daily build at 1-5 9 o'clock in the morning per week, the crontab would be configured as follows:
0 9 * * * 1-5/users/tangqiao/dailybuild.sh >>/users/tangqiao/dailybuild.log 2>&1
|
Failure alarm
When the daily build script fails, it is best to send an alarm message or text message so that you can find it early. E-mails can be written in Python's smtplib, as shown in the following example:
Import Smtplib
Sender =' [Email protected] ' receivers = [' [Email protected] '
Message = "" "From:alert <[email protected]> To:some One <[email protected]> SUBJECT:SMTP Email Sample
Hope you can get it. """
Try obj = Smtplib. SMTP (' server.mail.devtang.com ') Obj.sendmail (sender, receivers, message) print ' ok:send Mail succeed ' Except Exception: print ' error:unable to send mail '
|
Upload
Daily build compiles if you need to upload to another web machine separately, you can use FTP or SCP protocol. If the Web machine tragedy is the Windows machine, you can open a share on the Windows machine, and then use the Mount-t Smbfs to mount the share to the local, the relevant sample code is as follows:
mkdir Upload Mount-t SMBFS//$SMB _username:[Email protected]$SMB _target./upload if ["$?"-ne0];Then Echo"Failed to mount SMB directory" Exit1 Fi mkdir./upload/ $FOLDER CP $FILE _name/upload/ $FOLDER/ if [ "$?" -eq 0]; then echo "[OK] $FILE _name is uploaded to else echo [ERROR] $FILE _name is FAILED-uploaded to $SMB _target " fi umount./upload |
Problems encountered
I wrote an automated script that works well under Mac OS X 10.6. However, when you upgrade to Lion, the script is normal when it is executed manually, but when you start with crontab, you cannot find a developer certificate error. Searched the internet for a long time and did not find a solution. Finally, I tried it. In keychain Access, drag the developer certificate from the "Log in" column to the "System" column and solve it, as shown in:
In addition, I found 2 similar problems of the solution, although for me this does not work, also put here, perhaps for people who encounter similar problems can help:
- Http://stackoverflow.com/questions/7635143/cannot-build-xcode-project-from-command-line-but-can-from-xcode
- http://shappy1978.iteye.com/blog/765842
Summarize
By combining the points above, you can write a daily build script with bash. Every day this will be done automatically, the mood is quite good.
Add daily Build to iOS project