Skip to content

Instantly share code, notes, and snippets.

@alabeduarte
Last active December 24, 2015 12:39
Show Gist options
  • Save alabeduarte/6798966 to your computer and use it in GitHub Desktop.
Save alabeduarte/6798966 to your computer and use it in GitHub Desktop.
Continuous Integration Build Script for iOS
#!/usr/bin/env bash
CI_PASSWORD="password"
security unlock-keychain -p ${CI_PASSWORD} /Users/Shared/Jenkins/Library/Keychains/login.keychain
if [ $? -ne 0 ]; then exit 1; fi
BUILD_DIR="/Users/Shared/CI/App/your_project/Build"
TARGET_SDK="iphoneos"
TARGET_TEST_SDK="iphonesimulator"
PRODUCT_NAME="YourProject"
SCHEME_NAME="YourProject"
TEST_NAME="YourProjectTests"
API_TOKEN='YOUR_TESTFLIGHT_API_TOKEN'
TEAM_TOKEN='YOUR_TESTFLIGHT_TEAM_TOKEN'
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
SIGNING_IDENTITY="Your Iphone Distribution Name"
PROVISIONING_PROFILE="/Users/Shared/CI/distribution.mobileprovision"
echo "********************"
echo "* Testing *"
echo "********************"
killall -m -KILL "iPhone Simulator"
xcodebuild -sdk "${TARGET_TEST_SDK}" -workspace "${PRODUCT_NAME}.xcworkspace" -scheme "${SCHEME_NAME}" -configuration Debug clean build ARCHS="i386" ONLY_ACTIVE_ARCH=NO SL_RUN_UNIT_TESTS=YES
xcodebuild -sdk "${TARGET_TEST_SDK}" -workspace "${PRODUCT_NAME}.xcworkspace" -scheme "${TEST_NAME}" -configuration Debug clean build ARCHS="i386" ONLY_ACTIVE_ARCH=NO SL_RUN_UNIT_TESTS=YES
if [ $? -ne 0 ]; then exit 1; fi
echo "********************"
echo "* Building *"
echo "********************"
xcodebuild -sdk "${TARGET_SDK}" -workspace "${PRODUCT_NAME}.xcworkspace" CONFIGURATION_BUILD_DIR="${BUILD_DIR}" -scheme "${SCHEME_NAME}" -configuration "Release" clean build ARCHS="armv7" ONLY_ACTIVE_ARCH=NO
if [ $? -ne 0 ]; then exit 1; fi
echo "********************"
echo "* Signing *"
echo "********************"
xcrun -sdk "${TARGET_SDK}" PackageApplication -v "${BUILD_DIR}/${PRODUCT_NAME}.app" -o "${BUILD_DIR}/${PRODUCT_NAME}.ipa" --sign "${SIGNING_IDENTITY}" --embed "${PROVISIONING_PROFILE}"
if [ $? -ne 0 ]; then exit 1; fi
echo "Created .ipa for ${PRODUCT_NAME}"
echo "************************************"
echo "* Uploading to TestFlight *"
echo "************************************"
/usr/bin/curl "http://testflightapp.com/api/builds.json" \
-F file=@${BUILD_DIR}/${PRODUCT_NAME}.ipa \
-F api_token="${API_TOKEN}" \
-F team_token="${TEAM_TOKEN}" \
-F notes="Build uploaded automatically from Continuous Integration Server." \
-F notify=True
if [ $? -ne 0 ]; then exit 1; fi
echo "************************************"
echo "* Uploaded to TestFlight *"
echo "************************************"
@tanob
Copy link

tanob commented Oct 8, 2013

Cool! Suggestion: you can also remove all instances of:

if [ $? -ne 0 ]; then exit 1; fi

and use the following in the beginning:

#!/usr/bin/env bash -e

-e or the command set -errexit will exit the shell script at any point where a command returns non-zero status code.

Cheers

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