How to configure Jenkins CI on Mac OS X to build Android- and iOS Phonegap/Cordova apps and deliver them to TestFlight/HockeyApp

In most cases, mobile apps development is a very exciting experience, particularly if you really enjoy what you do. As we are involved with a substantial number of external projects (mostly custom application and website development), with our native applications also rapidly growing in numbers, we took to minimize the time and effort we spend to build our releases and pre-releases. If you have multiple developers, testers, and lots of projects, the cost to build apps may become substantial. Therefore, to avoid time wastage and focus on really important service-oriented effort, we propose a guide on how to create a system to automatically build your apps. This approach we practice in our apps which we offer to your attention: Together, PhotoSuerte, Veranda.

  1. First of all, to build iOS apps you’ll certainly need a Mac
    • If you are using a Virtual Private Server (VPS), to save resources it is better to disable Spotlight on it (Settings > Spotlight > Privacy > + > Add the entire drive)
    • The requirements for the machine are minimal, just 512 MB of RAM are sufficient, and the faster the CPU, the quicker your build
    • You can build your app either on a physical Mac device or on a virtual server (for example, Hostmyapple, Gekkoit, or Xcloud)
  2. Install and configure Jenkins
    • Install Java Runtime
    • Enable SSH and connect to the console
    • Use the following console command to download the latest Jenkins version:wget -O jenkins-latest.pkg http://mirrors.jenkins-ci.org/osx/latest
    • Install Jenkins by command:sudo installer -pkg jenkins-latest.pkg -target /
    • The installation creates the jenkins user with the home directory /Users/Shared/Jenkins
    • If necessary, install JRE and Apache Ant
    • Reboot your Mac and make sure that Jenkins runs and listens on port 8080.
  3. In Jenkins, open the Manage Jenkins/Manage Plugins section to install the following plugins:
  4. Install Xcode from the App Store, using your Apple ID
  5. Install Xcode Command Line Tools:
    • Run Xcode
    • In the Xcode/Preferences/Downloads menu,
    • click Download to the right of Command Line Tools
  6. Install Homebrew with the following command line commands:
    • ruby -e “$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)”
    • brew doctor
    • brew update
  7. Install nodejs and phonegap/cordova with the following commands:
    • brew install nodejs
    • npm -global install phonegap
    • npm -global install cordova
  8. Install Android SDK with the following commands:
    • Get a link to download SDK for Mac OS X 64-bit; run commands:
    • cd /Users/Shared/Jenkins/build_stuff
    • wget http://dl.google.com/android/adt/adt-bundle-mac-x86_64-20131030.zip
    • unzip adt-bundle-mac-x86_64-20131030.zip
    • ln -s adt-bundle-mac-x86_64-20131030 adt-bundle
    • As a result, Android SDK is installed in /Users/Shared/Jenkins/build_stuff/adt-bundle/sdk
    • Run utility /Users/Shared/Jenkins/build_stuff/adt-bundle/sdk/tools/android update sdk –no-ui and install all target versions

Let’s say that the application we build is called BlahApp.

Building Android Application

  1. In Jenkins, create the BlahApp-Android-build task
  2. Ask your developers for the ant.properties and BlahAppCertificate.keystroke files; put the latter into /Users/Shared/Jenkins/build_stuff/keystrokes
  3. Customize project code export by a GIT plugin from your workspace repository
    • To build your application automatically after a GIT push, you can use any of the methods described at Jenkins wiki
  4. Add the Invoke Ant build step with the following parameters:
    • Targets: release (or as indicated by developers, see build.xml)
    • Build file: platforms/android/build.xml
    • Properties: These parameters are usually found in local.properties and ant.properties; here they are entered as command line parameters at Ant launch:
      • sdk.dir=/Users/Shared/Jenkins/build_stuff/adt-bundle/sdk
      • key.store=/Users/Shared/Jenkins/build_stuff/keystores/BlahAppCertificate.keystore
      • key.alias=BlahApp
      • key.store.password=********
      • key.alias.password=********
  5. After that, you can check the build and discuss with the developer applicable parameters, SDK versions, etc., if the build fails for some reason
  6. Delivery of files of the app you have built
    • File archiving, step Post-build action/Archive the artifact with parameters:
      • Files to archive: platforms/android/bin/*.apk
    • FTP delivery, step Post-build action/Send build artifacts over FTP with the following parameters:
      • Before starting this step, create an FTP account in the global Jenkins settings
      • FTP Server Name: select the account needed
      • Source files: platforms/android/bin/*.apk
      • Remove prefix: platforms/android/bin/
      • Remote directory: BlahApp/Android/${BUILD_ID}_${BUILD_NUMBER}
    • SSH delivery, step Post-build action/Send build artifacts over SSH with the following parameters:
      • create an SSH account in advance in the global Jenkins settings
      • SSH Server Name: select the account needed
      • Source files: platforms/android/bin/*.apk
      • Remove prefix: platforms/android/bin/
      • Remote directory: BlahApp/Android/${BUILD_ID}_${BUILD_NUMBER}
  7. Upload to TestFlight
    • Create a valid account in Testflight
    • Get an API token
    • Get a Team token
    • Create a Token Pair from both of the above tokens in the Jenkins settings Test Flight section
    • Add the Post-build action/Upload to Testflight step with the following parameters:
      • Token Pair: choose the above-created
      • IPA/APK Files: platforms/android/bin/*.apk
      • dSYM File: leave this blank
      • Enable option: Append changelog to build notes
  8. Delivery by e-mail, step Post-build action/Editable Email Notification with the following parameters:
    • Attachments: platforms/android/bin/*.apk
    • Attach Build Log: Compress and Attach Build Log

Building iOS Application

  1. Configure certificates and profiles
    • Get the application signature certificates and the profile from your developers
    • In the Keychain Access utility, create xcode.keychain and set a password to open it
    • Put certificates inside it and disable, for all certificates, restrictions on application access (see wiki)
    • In the Jenkins settings, add xcode.keychain to the list of keychains in Xcode Builder section, specifying a file path and password
    • Put the profile file to directory /Users/Shared/Jenkins/Library/MobileDevice/Provisioning Profiles
  2. Create the BlahApp-build-iOS task in Jenkins
  3. Configure how a Git-plugin will export the project code from the repository to the workspace.
  4. To enable automatic application build on pushing the code to GIT, you can use any of the methods specified in the wiki:
  5. To manually download the sub-modules, do the following:
    • enable the Disable submodules processing option
    • add the first build step Execute shell with code «git submodule update – init – recursive»
  6. Add the Xcode build step with the following parameters:
    • Enable Clean before build
    • Configuration: Release
    • Enable: Pack application and build. Ipa
    • Code Signing Identity: name of the signatory to whom the certificate has been issued, for example: iPhone Distribution: DENIVIP Media OOO (SQ12345678)
    • Embedded Profile: path to the signatory’s profile, e.g., /Users/Shared/Jenkins/build_stuff/profiles/4FF5AFF9-DD63-4881-9B69-941D166F1C37.mobileprovision
    • Enable Unlock keychain and select the profile from (1)
    • Xcode Schema File: request from the developers
    • Xcode Project Directory: platforms/ios
    • Build Output Directory: built-project
  7. Delivery of files of your built applications
    • Archiving of files, step Post-build action/Archive the artifact with parameters:
      • Files to archive: built-project/*. ipa,built-project/*.zip
    • Delivery via FTP, step Post-build action/Send build artifacts over FTP with the following parameters:
      • Before starting this step, create an FTP account in the global Jenkins settings
      • FTP Server Name: select a relevant account
      • Source files: built-project/*.ipa
      • Remove prefix: built-project/
      • Remote directory: BlahApp/iOS/${BUILD_ID}_${BUILD_NUMBER}
    • SSH delivery, step Post-build action/Send build artifacts over SSH with parameters:
      • Before starting this step, create an SSH account in the global Jenkins settings
      • SSH Server Name: select a relevant account
      • Source files: built-project/*.ipa
      • Remove prefix: built-project/
      • Remote directory: BlahApp/iOS/${BUILD_ID}_${BUILD_NUMBER}
    • TestFlight delivery
      • Create a valid account in Testflight
      • Get an API token
      • Get a Team token
      • Create a Token Pair from both of the above tokens in the Jenkins settings Test Flight section
      • Add the Post-build action/Upload to Testflight step with the following parameters:
        • Token Pair: choose the one created above
        • IPA / APK Files: built-project/*.ipa
        • dSYM File: leave blank
        • Enable option: Append changelog to build notes
      • Token Pair: choose the one created above
      • IPA / APK Files: built-project/*.ipa
      • dSYM File: leave blank
      • Enable option: Append changelog to build notes
  8. HockeyApp delivery
    • Create a valid account in HockeyApp
    • Get an API token and a Public ID/App ID
    • Add step Post-build action/Upload to HockeyApp, with the following parameters:
    • API Token: choose the one created above
    • Public ID/App ID: choose the one created above
    • App file: built-project/*.ipa
    • Symbols: built-project/*-dsym.zip
  9. E-mail delivery, step Post-build action/Editable Email Notification with the following parameters:
    • Attachments: built-project/*.ipa
    • Attach Build Log: Compress and Attach Build Log

Leave a Reply