Skip to content

Instantly share code, notes, and snippets.

@barbosa
Created January 2, 2015 23:13
Show Gist options
  • Select an option

  • Save barbosa/d0e9a75ceb2ba07c97b1 to your computer and use it in GitHub Desktop.

Select an option

Save barbosa/d0e9a75ceb2ba07c97b1 to your computer and use it in GitHub Desktop.

Revisions

  1. barbosa created this gist Jan 2, 2015.
    89 changes: 89 additions & 0 deletions jenkins-xcodebuild
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,89 @@
    # source: http://www.raywenderlich.com/downloads/jenkins_shell_steps.txt

    #####################
    # JENKINS step #1
    # add to it's own execute shell section
    #####################

    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer

    xcodebuild -target GuildBrowserLogicTests \
    -sdk iphonesimulator \
    -configuration Debug \
    TEST_AFTER_BUILD=YES \
    clean build | /usr/local/bin/ocunit2junit.rb

    #####################
    # JENKINS STEP #2
    # add to it's own execute shell section
    #####################
    # tests passed archive app

    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer

    /usr/bin/xcrun xcodebuild -scheme GuildBrowser clean archive \
    CODE_SIGN_IDENTITY="iPhone Distribution: Charles Fulton"

    echo "App Archived"

    #####################
    # JENKINS STEP #3
    # add to it's own execute shell section
    #####################
    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer

    # testflight stuff
    API_TOKEN=<insert yours>
    TEAM_TOKEN=<insert yours>

    #
    # Setup
    #
    # 1
    PROJECT="GuildBrowser"
    SIGNING_IDENTITY="iPhone Distribution: Charles Fulton"
    PROVISIONING_PROFILE="${WORKSPACE}/Charles_Fulton_All_Ad_Hoc.mobileprovision"

    # 2
    # this is the latest archive from previous build step
    ARCHIVE="$(ls -dt ~/Library/Developer/Xcode/Archives/*/${PROJECT}*.xcarchive|head -1)"
    # 3
    IPA_DIR="${WORKSPACE}"
    DSYM="${ARCHIVE}/dSYMs/${PROJECT}.app.dSYM"
    APP="${ARCHIVE}/Products/Applications/${PROJECT}.app"


    #
    # PackageApplication
    #

    # package up the latest archived build
    /bin/rm -f "${IPA_DIR}/${PROJECT}.ipa"

    # 4
    /usr/bin/xcrun -sdk iphoneos PackageApplication \
    -o "${IPA_DIR}/${PROJECT}.ipa" \
    -verbose "${APP}" \
    -sign "${SIGNING_IDENTITY}" \
    --embed "${PROVISIONING_PROFILE}"

    # zip and ship
    /bin/rm -f "${IPA_DIR}/${PROJECT}.dSYM.zip"

    # 5
    /usr/bin/zip -r "${IPA_DIR}/${PROJECT}.dSYM.zip" "${DSYM}"


    #
    # Send to test flight
    #
    /usr/bin/curl "http://testflightapp.com/api/builds.json" \
    -F file=@"${IPA_DIR}/${PROJECT}.ipa" \
    -F dsym=@"${IPA_DIR}/${PROJECT}.dSYM.zip" \
    -F api_token="${API_TOKEN}" \
    -F team_token="${TEAM_TOKEN}" \
    -F notes="Build ${BUILD_NUMBER} uploaded automatically from Xcode. Tested by Chuck Norris" \
    -F notify=True \
    -F distribution_lists='all'

    echo "Successfully sent to TestFlight"