Skip to content

Instantly share code, notes, and snippets.

@johanneswuerbach
Last active May 14, 2024 03:50
Show Gist options
  • Save johanneswuerbach/5559514 to your computer and use it in GitHub Desktop.
Save johanneswuerbach/5559514 to your computer and use it in GitHub Desktop.
Deploy an iOS app to testflight using Travis CI
---
language: objective-c
before_script:
- ./scripts/travis/add-key.sh
after_script:
- ./scripts/travis/remove-key.sh
after_success:
- ./scripts/travis/testflight.sh
env:
global:
- APPNAME="NAME_OF_THE_APP"
- 'DEVELOPER_NAME="iPhone Distribution: NAME_OF_THE_DEVELOPER (CODE)"'
- PROFILE_UUID=PROVISIONING_PROFILE_UUID

Deploy an app automatically to testflight using travis ci.

  1. Copy the .travis.yml into your repo (replace app name, developer name and provisionin profile uuid)
  2. Create the folder "scripts/travis"
  3. Export the following things from the Keychain app
  4. "Apple Worldwide Developer Relations Certification Authority" into scripts/travis/apple.cer
  5. Your iPhone Distribution certificate into scripts/travis/dist.cer
  6. Your iPhone Distribution private key into scripts/travis/dist.p12 (choose a password)
  7. Execute travis encrypt "KEY_PASSWORD=YOUR_KEY_PASSWORD" --add
  8. Execute travis encrypt "TEAM_TOKEN=TESTFLIGHT_TEAM_TOKEN" --add
  9. Execute travis encrypt "API_TOKEN=TESTFLIGHT_API_TOKEN" --add
  10. Copy add-key.sh, remove-key.sh and testflight.sh into scripts/travis
  11. Commit
security create-keychain -p travis ios-build.keychain
security import ./scripts/travis/apple.cer -k ~/Library/Keychains/ios-build.keychain -T /usr/bin/codesign
security import ./scripts/travis/dist.cer -k ~/Library/Keychains/ios-build.keychain -T /usr/bin/codesign
security import ./scripts/travis/dist.p12 -k ~/Library/Keychains/ios-build.keychain -P $KEY_PASSWORD -T /usr/bin/codesign
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp ./scripts/travis/profile/* ~/Library/MobileDevice/Provisioning\ Profiles/
security delete-keychain ios-build.keychain
rm -f ~/Library/MobileDevice/Provisioning\ Profiles/*
#!/bin/sh
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then
echo "This is a pull request. No deployment will be done."
exit 0
fi
if [[ "$TRAVIS_BRANCH" != "master" ]]; then
echo "Testing on a branch other than master. No deployment will be done."
exit 0
fi
# Thanks @djacobs https://gist.github.com/djacobs/2411095
PROVISIONING_PROFILE="$HOME/Library/MobileDevice/Provisioning Profiles/$PROFILE_UUID.mobileprovision"
RELEASE_DATE=`date '+%Y-%m-%d %H:%M:%S'`
OUTPUTDIR="$PWD/build/Release-iphoneos"
echo "********************"
echo "* Signing *"
echo "********************"
xcrun -log -sdk iphoneos PackageApplication "$OUTPUTDIR/$APPNAME.app" -o "$OUTPUTDIR/$APPNAME.ipa" -sign "$DEVELOPER_NAME" -embed "$PROVISIONING_PROFILE"
RELEASE_NOTES="Build: $TRAVIS_BUILD_NUMBER\nUploaded: $RELEASE_DATE"
zip -r -9 "$OUTPUTDIR/$APPNAME.app.dSYM.zip" "$OUTPUTDIR/$APPNAME.app.dSYM"
echo "********************"
echo "* Uploading *"
echo "********************"
curl http://testflightapp.com/api/builds.json \
-F file="@$OUTPUTDIR/$APPNAME.ipa" \
-F dsym="@$OUTPUTDIR/$APPNAME.app.dSYM.zip" \
-F api_token="$API_TOKEN" \
-F team_token="$TEAM_TOKEN" \
-F distribution_lists='Internal' \
-F notes="$RELEASE_NOTES" -v
@davebcn87
Copy link

With the last update of Travis CI machines to Mavericks you should add this lines to add-key.sh before creating keychain:

security default-keychain -s ios-build.keychain
security unlock-keychain -p travis ios-build.keychain

@JagCesar
Copy link

JagCesar commented May 8, 2014

If you have ! in your password, don't forget to escape it… :)

@JagCesar
Copy link

JagCesar commented May 9, 2014

I have forked this and updated it so it works on Travis-CI (We're using it here at Wrapp now). I have also updates the README, hopefully it's easier to get it up and running :)

You find my fork at:
https://gist.github.com/JagCesar/a6283bc2cb2f439b3a1d

@boekkooi
Copy link

When you unlock the keychain it maybe locked later on due to a timeout.
You can prevent this by adding security -v set-keychain-settings -lut 86400 ios-build.keychain in add-key.sh.
This will set the keychain timeout to 24 hours and that should be enough to build your app.

Special Thanks to Jay Zeschin (http://modeset.com/what-we-know/2013/03/11/jenkins_keychain_timeouts)

@taberrr
Copy link

taberrr commented Jul 5, 2014

To anyone getting that cp: ./scripts/travis/profile/*: No such file or directory error - I think there should be a "step 2a." above which should be: mkdir scripts/travis/profile then copy your appropriate Ad Hoc/Enterprise .mobileprovision file into that directory and commit it.

@pbek
Copy link

pbek commented Oct 31, 2015

Thank you @johanneswuerbach for this tutorial and thank you @davebcn87 for your addition!

@fuer4869
Copy link

fuer4869 commented Nov 3, 2015

@kaspermunck I met an issue with @crazycabo ,and i follow your answer to do it.But it still failed.

./scripts/sign-and-upload.sh
/Users/travis/build.sh: line 41: ./scripts/sign-and-upload.sh: Permission denied

$ chmod +x scripts/add-key.sh
$ chmod +x scripts/remove-key.sh

and the certificate has been import success
1 certificate imported.
1 certificate imported.
1 identity imported.

I don't know how to do next , please help me !

@magusd
Copy link

magusd commented Nov 4, 2015

The chmod +x worked for me and I'm not even deploying to testflight.
Thanks man

@christopherstott
Copy link

You might be interested in trying www.buddybuild.com as a simple alternative to scripting a basic CI.

@SuRuiGit
Copy link

@fuer4869 I met an issue with you,how to do next?

@dholdaway
Copy link

i dont think the test flight upload works due to the apple deal, can anyone confirm this?

@wethinkagile
Copy link

Is Travis CI capable of building and shipping my Ionic 2 app to Testflight / Hockey or direct install on the iPhones of my organisation? Thank you

@fenollp
Copy link

fenollp commented Nov 26, 2016

@LarryChuksGitHub
Copy link

AWESOME!!

@simerjeet-ucreate
Copy link

Hey,
I am working with this and not able to get how to create a TESTFLIGHT_API_TOKEN. Can someone please explain how we can generate that directly from developer.Testflight "https://developer.apple.com/testflight/" site. Thanks!!

@toddpi314
Copy link

Are you based in Berlin by chance?

image

@surekhas-tml
Copy link

Hi,
for deploying over github, how to write travis script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment