Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Jenkins for iOS Apps by Bruce Shankle

Jenkins for iOS Apps by Bruce Shankle

Slides from Bruce Shankle's talk on using Jenkins to build iOS applications at CocoaHeads June 2012 in Raleigh, NC

Triangle Cocoa

June 30, 2012
Tweet

More Decks by Triangle Cocoa

Other Decks in Programming

Transcript

  1. Trivia • Jenkins was the butler of Daphne Blake from

    the cartoon Scooby Doo. • Jenkins used to be called Hudson until the Oracle corporation trademarked Hudson. So the guys who wrote Hudson, renamed it to Jenkins and kept on developing on it. (There are plenty of butler names left it this one doesn’t work out...)
  2. • A show of hands... • What is Jenkins: one

    of many continuous integration systems • What is a continous integration system?
  3. Continuous Integration? • This is a very fancy name for

    what these things actually do. • So....let’s make our own with a few lines of script...
  4. Meet Alfred #!/bin/bash #Alfred CI - by Bruce Shankle #One

    infinite loop while : do #Do useful stuff here. echo "I am Alfred, and I am here to serve you." FILECOUNT=$(ls -b | wc -l | tr -d ' ') echo "I see $FILECOUNT files." if [ $FILECOUNT -ne "1" ]; then echo "There are too many files." fi #Wait a bit echo "Alfred will rest a while now." sleep 5 done
  5. Continuous Integration • Automation that applies a sequence of operations

    to code ‘frequently’ with an aim to improve the quality of the software by notifying a human when something does not compile, run, or pass a test. • Frequency: Every time the code changes or on a regular basis (hourly, nightly, weekly)... • Operations: Pull, Compile, Test, Package, Deploy • Notify: web page, reports, email
  6. How we use Jenkins • We do a weekly ‘drop’

    of our SDK, tools, and reference applications. • I have Jenkins set up on my laptop (but we really should be using a separate machine) • We manually kick off a build for our drop. git pull, xcodebuild, xcrun, appledoc, create a TestFlight package, and zip everything up. • It used to take me about 2 hours to manually build a drop. Now it is just a few minutes because moving to Jenkins forced me to automate everything
  7. What we’re not should but could / should... • We

    could be building our linux binaries on one of our linux servers using Jenkin’s node management system • We could be having Jenkins run automated UI tests using accessibility features of iOS and some cool tech Josh showed us last week • We could be having Jenkins run non-graphical unit tests.
  8. Reference Slides • These next few slides are for reference

    in case you plan to use Jenkins for your iOS projects
  9. Jenkins - User • If you install the binary package,

    it will create a sort of pseduo-user on your system named jenkins. You’ll want to make that a ‘real’ user if you’re building signed iOS projects due to key-chain / certificate issues sudo dscl . create /Users/jenkins sudo dscl . create /Users/jenkins PrimaryGroupID 1 sudo dscl . create /Users/jenkins UniqueID 300 sudo dscl . create /Users/jenkins UserShell /bin/bash sudo dscl . create /Users/jenkins home /Users/Shared/Jenkins/Home/ sudo dscl . create /Users/jenkins NFSHomeDirectory /Users/Shared/Jenkins/ Home/ sudo dscl . passwd /Users/jenkins
  10. Jenkins - User Now that you have created the user,

    it’s time to tell the LaunchAgent that came with the install package to use this user to run Jenkins. The file you have to change for this is located at /Library/LaunchDaemons/org.jenkins-ci.plist . Just open it in your favorite editor and change the value of UserName to jenkins: <key>UserName</key> <string>jenkins</string> After doing that, the Home folder of jenkins, /Users/Shared/Jenkins/Home needs a new owner. sudo chown -R jenkins /Users/Shared/Jenkins After doing all that, saving the modified launch file and chown’ing the Home, unload and reload the service: sudo launchctl unload -w /Library/LaunchDaemons/org.jenkins-ci.plist sudo launchctl load -w /Library/LaunchDaemons/org.jenkins-ci.plist
  11. If you need to do code-signing: You need to export

    you developer key/cert and distrubtion key/cert to files. Go to keys in KeyChain access, find your developer key and expand it. Highlight it and the cert, right click and choose “Export 2 items”. Save to a file and give it a password. Do the same thing for your distribution key. You have to export the key and the certificate together. You should end up with two password protected .p12 files. Copy these files to the Jenkins home folder. Log in as the Jenkins user and set up the keychain: security create-keychain -p jenkins appledev security default-keychain -s appledev Now you import your distribution key and certificate into the new keychain: security import developer_cert_and_key.p12 -k appledev -f pkcs12 -A -P <your_pkcs12_password> security import distribution_cert_and_key.p12 -k appledev -f pkcs12 -A -P <your_pkcs12_password> Before doing any code signing you’ll need to unloack the keychain. This should be done in your Jenkins script: security unlock-keychain -p jenkins /Users/Shared/Jenkins/Home/Library/ Keychains/appledev
  12. Jenkins - Code Sign • You need to copy your

    provisioning profiles to: / Users/Shared/Jenkins/Home/Library/MobileDevice/ Provisioning • One of your commands has to be to unlock the keychain: security unlock-keychain -p jenkins /Users/Shared/Jenkins/Home/ Library/Keychains/appledev
  13. Jenkins - Other • Learn about xcodebuild and xcrun for

    building and signing iOS apps from the command line • Use command line steps to build and sign your iOS apps • Use a Jenkins-scheme in your project • If you have the means, try to run Jenkins on
  14. Jenkins - Gotchas • Making code-signed TestFlight-ready binaries is a

    pain. Sometimes we have to restart Jenkins because it can’t code-sign. I blame Apple. Could be related to my machine sleeping / resuming? • If you plan to use Jenkins for doing code- signing you’re going to end up doing most of the work in scripts, the plug-in scene is a