Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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
@joshk

This comment has been minimized.

Show comment Hide comment
@joshk

joshk May 11, 2013

OMG OMG OMG THIS IS AWESOME!!!

We need to wrap some of this up into Travis to make it easier for everyone!

❤️❤️❤️

joshk commented May 11, 2013

OMG OMG OMG THIS IS AWESOME!!!

We need to wrap some of this up into Travis to make it easier for everyone!

❤️❤️❤️

@joshk

This comment has been minimized.

Show comment Hide comment
@joshk

joshk May 11, 2013

Are you based in Berlin by chance?

joshk commented May 11, 2013

Are you based in Berlin by chance?

@soffes

This comment has been minimized.

Show comment Hide comment
@soffes

soffes May 11, 2013

❤️

soffes commented May 11, 2013

❤️

@moredip

This comment has been minimized.

Show comment Hide comment
@moredip

moredip May 11, 2013

AWESOME

moredip commented May 11, 2013

AWESOME

@johanneswuerbach

This comment has been minimized.

Show comment Hide comment
@johanneswuerbach

johanneswuerbach May 11, 2013

@joshk no currently in SF

Owner

johanneswuerbach commented May 11, 2013

@joshk no currently in SF

@joshk

This comment has been minimized.

Show comment Hide comment
@joshk

joshk May 12, 2013

Drat, we are all based in Berlin and I wanted to buy you a beer and give you a big jumping high 5 to say thanks!

joshk commented May 12, 2013

Drat, we are all based in Berlin and I wanted to buy you a beer and give you a big jumping high 5 to say thanks!

@johanneswuerbach

This comment has been minimized.

Show comment Hide comment
@johanneswuerbach

johanneswuerbach May 13, 2013

Thanks, I'll be back in Berlin beginning of July. Let's talk again than.

Owner

johanneswuerbach commented May 13, 2013

Thanks, I'll be back in Berlin beginning of July. Let's talk again than.

@joshk

This comment has been minimized.

Show comment Hide comment
@joshk

joshk May 14, 2013

Make sure you get in touch, coffee/beers on me! :)

joshk commented May 14, 2013

Make sure you get in touch, coffee/beers on me! :)

@tulushev

This comment has been minimized.

Show comment Hide comment
@tulushev

tulushev May 30, 2013

Thanks, it's working perfectly)

Thanks, it's working perfectly)

@ferbass

This comment has been minimized.

Show comment Hide comment
@ferbass

ferbass Jul 4, 2013

<3 thanks man

ferbass commented Jul 4, 2013

<3 thanks man

@neophit

This comment has been minimized.

Show comment Hide comment
@neophit

neophit Jul 8, 2013

@joshk any updates on integrating these scripts into Travis to make it easier for everyone? I would like to have a secure place in my Travis CI profile to upload my iOS developer certificates and private keys instead of committing them in public Github repositories. I know the private key is password protected, but I would prefer to keep sensitive data outside of public repositories.

neophit commented Jul 8, 2013

@joshk any updates on integrating these scripts into Travis to make it easier for everyone? I would like to have a secure place in my Travis CI profile to upload my iOS developer certificates and private keys instead of committing them in public Github repositories. I know the private key is password protected, but I would prefer to keep sensitive data outside of public repositories.

@joshk

This comment has been minimized.

Show comment Hide comment
@joshk

joshk Jul 9, 2013

Hey @neophit,

Yes and no. We want to add this but haven't had the time yet sorry. We also want to allow people to add certs or secure env vars in the UI and not have to store them in your git repo, but this is going to take longer.

If you would like to help out with this, in any shape or form, please email josh or henrik @travis-ci.com

Thanks a bundle,

Josh

joshk commented Jul 9, 2013

Hey @neophit,

Yes and no. We want to add this but haven't had the time yet sorry. We also want to allow people to add certs or secure env vars in the UI and not have to store them in your git repo, but this is going to take longer.

If you would like to help out with this, in any shape or form, please email josh or henrik @travis-ci.com

Thanks a bundle,

Josh

@seivan

This comment has been minimized.

Show comment Hide comment
@seivan

seivan Jul 28, 2013

So goood. <3

seivan commented Jul 28, 2013

So goood. <3

@crazycabo

This comment has been minimized.

Show comment Hide comment
@crazycabo

crazycabo Oct 29, 2013

Does this process still function. I have tried for several hours to find my provisioning profile UUID and cannot with Xcode 5. I continue to receive:

/Users/travis/build.sh: line 215: ./scripts/travis/add-key.sh: Permission denied

I have confirmed the encrypted key password is correct.

Does this process still function. I have tried for several hours to find my provisioning profile UUID and cannot with Xcode 5. I continue to receive:

/Users/travis/build.sh: line 215: ./scripts/travis/add-key.sh: Permission denied

I have confirmed the encrypted key password is correct.

@kaspermunck

This comment has been minimized.

Show comment Hide comment
@kaspermunck

kaspermunck Nov 21, 2013

@crazycabo add-key.sh and remove-key.sh are creating and removing a directory, respectively. Try to give those files appropriate permissions:

before_install:
- chmod +x scripts/travis/add-key.sh
- chmod +x scripts/travis/remove-key.sh

@crazycabo add-key.sh and remove-key.sh are creating and removing a directory, respectively. Try to give those files appropriate permissions:

before_install:
- chmod +x scripts/travis/add-key.sh
- chmod +x scripts/travis/remove-key.sh
@hpogosyan

This comment has been minimized.

Show comment Hide comment
@hpogosyan

hpogosyan Dec 16, 2013

Can someone please help? I am getting this error in my Travis Build Log:

$ ./scripts/travis/add-key.sh
1 certificate imported.
1 certificate imported.
cp: ./scripts/travis/profile/*: No such file or directory
The command "./scripts/travis/add-key.sh" failed and exited with 1 during before_script.
Your build has been stopped.

Can someone please help? I am getting this error in my Travis Build Log:

$ ./scripts/travis/add-key.sh
1 certificate imported.
1 certificate imported.
cp: ./scripts/travis/profile/*: No such file or directory
The command "./scripts/travis/add-key.sh" failed and exited with 1 during before_script.
Your build has been stopped.

@spenrose

This comment has been minimized.

Show comment Hide comment
@spenrose

spenrose Jan 23, 2014

I am having the same problem with not being able to create the provisioning profiles directory. Anyone know how to do this now?

I am having the same problem with not being able to create the provisioning profiles directory. Anyone know how to do this now?

@paulyoung

This comment has been minimized.

Show comment Hide comment
@paulyoung

paulyoung Jan 31, 2014

@hpogosyan - did you get this working?

@spenrose - see the comment by kaspermunck.

@hpogosyan - did you get this working?

@spenrose - see the comment by kaspermunck.

@paulyoung

This comment has been minimized.

Show comment Hide comment
@paulyoung

paulyoung Jan 31, 2014

I was also having this issue:

cp: ./scripts/travis/profile/[NAME].mobileprovision: No such file or directory

In my case, my .gitignore file had a rule to ignore directories called "profile".

I added the following and committed the directory which fixed the issue:

!scripts/profile

I was also having this issue:

cp: ./scripts/travis/profile/[NAME].mobileprovision: No such file or directory

In my case, my .gitignore file had a rule to ignore directories called "profile".

I added the following and committed the directory which fixed the issue:

!scripts/profile

@breerly

This comment has been minimized.

Show comment Hide comment
@breerly

breerly Feb 11, 2014

First of all. Thanks a lot. I think that continuous delivery of iOS apps will be a mainstream thing very soon.

Might I suggest moving this to a genuine repo so that it can be worked on in a more productive way?

breerly commented Feb 11, 2014

First of all. Thanks a lot. I think that continuous delivery of iOS apps will be a mainstream thing very soon.

Might I suggest moving this to a genuine repo so that it can be worked on in a more productive way?

@gibo

This comment has been minimized.

Show comment Hide comment
@gibo

gibo Apr 14, 2014

@hpogosyan did you find a solution?

I'm also getting this error
cp: ./scripts/travis/profile/*: No such file or directory

gibo commented Apr 14, 2014

@hpogosyan did you find a solution?

I'm also getting this error
cp: ./scripts/travis/profile/*: No such file or directory

@davebcn87

This comment has been minimized.

Show comment Hide comment
@davebcn87

davebcn87 Apr 24, 2014

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

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

This comment has been minimized.

Show comment Hide comment
@JagCesar

JagCesar May 8, 2014

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

JagCesar commented May 8, 2014

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

@JagCesar

This comment has been minimized.

Show comment Hide comment
@JagCesar

JagCesar 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

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

This comment has been minimized.

Show comment Hide comment
@boekkooi

boekkooi May 13, 2014

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)

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

This comment has been minimized.

Show comment Hide comment
@taberrr

taberrr 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.

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

This comment has been minimized.

Show comment Hide comment
@pbek

pbek Oct 31, 2015

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

pbek commented Oct 31, 2015

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

@fuer4869

This comment has been minimized.

Show comment Hide comment
@fuer4869

fuer4869 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 !

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

This comment has been minimized.

Show comment Hide comment
@magusd

magusd Nov 4, 2015

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

magusd commented Nov 4, 2015

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

@christopherstott

This comment has been minimized.

Show comment Hide comment
@christopherstott

christopherstott Jan 19, 2016

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

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

@SuRuiGit

This comment has been minimized.

Show comment Hide comment
@SuRuiGit

SuRuiGit Feb 18, 2016

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

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

@dholdaway

This comment has been minimized.

Show comment Hide comment
@dholdaway

dholdaway Apr 1, 2016

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

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

@nottinhill

This comment has been minimized.

Show comment Hide comment
@nottinhill

nottinhill Jul 21, 2016

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

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

This comment has been minimized.

Show comment Hide comment
@LarryChuksGitHub

This comment has been minimized.

Show comment Hide comment
@LarryChuksGitHub

LarryChuksGitHub Mar 17, 2017

AWESOME!!

AWESOME!!

@simerjeet-ucreate

This comment has been minimized.

Show comment Hide comment
@simerjeet-ucreate

simerjeet-ucreate Dec 1, 2017

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!!

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!!

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