Friday, July 17, 2009

iPhone app distribution made easy - Part 4

Introducing Subversion
One of the most important items for any kind of software development is a version/revision control system. There are many flavors of version control systems and many arguments for and against each one. Ultimately they all provide the ability to track changes in code over time and provide the ability to manage development paths. For the purpose of this post I'll be referencing SubVersion (http://subversion.tigris.org/).

Introducing Hudson
Hudson is a continuous integration build system that enables easy tracking and running of builds. Hudson can be downloaded from https://hudson.dev.java.net/ and is very easy to get started and can be run on the Mac with the following command "java -jar hudson.war".

Hudson is integrated with subversion so builds can be triggered by subversion code commits. Builds can also be launched manually. One of the great strengths of Hudson is that it manages all the build numbers and build artifacts for you so you don't have to think about it.

Basic steps
The steps to get Hudson building your iPhone applications are quite simple and follows the format:


  1. Create a new hudson job

  2. Point Hudson to your subversion repository

  3. Create a build step to run the build scripts developed earlier in Part 2 and Part 3.

  4. Instruct Hudson to save the build output.


Example Build step
The following build step starts by creating some variables for build folders etc using some of Hudson's built in environment variables. It then builds the AppStore and AdHoc distributions.

PROJDIR=${WORKSPACE}/myApp
ADHOC_BUILDDIR="${PROJDIR}/build/myAppAdHoc/DistributionAdHoc-iphoneos"
APPSTORE_BUILDDIR="${PROJDIR}/build/myAppAppStore/DistributionAppStore-iphoneos"
BASEFILENAME="${JOB_NAME}_${BUILD_NUMBER}(rev-${SVN_REVISION})"

echo Building AppStore release
cd "${PROJDIR}"
xcodebuild -target "myAppAppStore" -configuration "DistributionAppStore" -sdk iphoneos2.1
cd "${APPSTORE_BUILDDIR}"
zip -r -T -y "${BASEFILENAME}_AppStoreApp.zip" "myApp.app"

echo Building AdHoc release
cd "${PROJDIR}"
xcodebuild -target "myAppAdHoc" -configuration "DistributionAdHoc" -sdk iphoneos2.1
cd "${ADHOC_BUILDDIR}"
zip -r -T -y "${BASEFILENAME}_AdHocApp.zip" "myApp.app"


The output zip file name will include the build number & subversion revision number for easy reference.

Example: myApp_13(rev-99619)_ProdApp.zip

Example artifacts archive
Hudson has the ability to perform wild card searches when looking for build artifacts. The following will search both the AdHoc and AppStore build folders for their output files.

myApp/build/**/*.zip

Conclusion
So hopefully you are now inspired or atleast aware of how you can make your own iPhone development easier.

6 comments:

  1. I've been wanting to get automated builds of my iPhone apps running for quite some time, so thank you for pointing me at the command-line tool xcodebuild.

    After setting up my automated builds however, I'm running into keychain login problems though. How did you manage to work around Keychain Access requiring a password before continuing?

    I'm running Hudson on a remote Linux machine, and ssh onto my OSX build box to run my builds. Did you have any similar problems?

    ReplyDelete
  2. I'm sorry but I didn't experience any keychain issues. I'm running Hudson on the same Mac that is building the projects.

    Have you looked into storing your ssh-agent passphrase in the keychain?

    http://www-uxsup.csx.cam.ac.uk/~aia21/osx/leopard-ssh.html

    ReplyDelete
  3. Thanks for this series, I had been trying to figure out how to setup a continuous build server, and this is a great example!

    ReplyDelete
  4. Thanks for your wothful post. I just ran into the same keychain issuse as Mike (probably). It is necessary to import all required keys into the login keychain of the user running hudson. The login keychain isn't unlocked when the login is via ssh, so you have to unlock manually:

    security unlock -p securePassword /Users/hudsonUser/Library/Keychains/login.keychain

    ReplyDelete
  5. Thanks for your post. Very interesting indeed.
    Are you aware of a mechanism that would automate the publication of the app to the App Store?
    I would like to add a Hudson job which includes build but also submission. Is it something possible?
    Thanks

    ReplyDelete
  6. Thanks for this post.

    I have silly question for hudson. You said that "hudson is very easy to get started and can be run on the Mac with the following command "java -jar hudson.war"". But after download the hudson.war when I run the command you provide, is always says this : "Initial setup required. Please go to the Hudson Dashboard and complete the setup.". I tried to much where to do initial setup, but I failed to solve this.

    I know you are not the guy with Hudson, but hope you can help me with this. Or you can guide me somewhere at i can find the solution.

    Thank you for your wonderful post.

    ReplyDelete