Product
How to customize the build process

Buddybuild automates a large majority of the complexity associated with setting up a mobile optimized continuous integration and continuous deployment solution.

It also has prebuilt integrations with tools you already use like GitHub, Bitbucket, Gitlab, Slack, HipChat, JIRA, Trello, Pivotal Tracker, iTunes Connect, TestFlight, the AppStore, Google Play and many others.

That said, teams sometimes need to customize the build process to accommodate their specific requirements.

To meet these needs, buddybuild can be extended through the use of scripts that are run at three points during the build:

  • After your repository has been cloned
  • Before a build
  • After a build

Buddybuild will check for the existence of specific files at each of these steps, and if they exist, will execute any commands that you specify.

You're free to install any tools or libraries that you'd like at these stages.

Post-Clone

The post-clone script is run immediately after git clone, and before buddybuild does any analysis of what is in the repo.

Buddybuild users often take advantage of the post-clone step to generate or modify their xcodeproject (e.g., some React Native and Cordova projects require this) or to expose git information (e.g., the author and/or the revision SHA for the build).

Simply create and check-in a file called buddybuild_postclone.sh in the root of your repository.

Pre-Build

The pre-build script is run before the build, but after any libraries / dependencies that your project requires have been installed.

You might want to use a custom pre-build step if you require some extra dependency compilation or want to customize your plist.

Simply check-in a file called buddybuild_prebuild.sh as a peer file to your .xcodeproj or build.gradle files.

Post-Build

The post-build script is run after a build has successfully completed.

Typically, the post-build step is used to upload specific artifacts to various service integrations you might have. You can find examples of the scripts needed to upload to HockeyApp and Crashlytics below.

Note: For iOS applications, the post build step will only run after code signing has been configured for your application. If the post build step is not running for you, please ensure that you've setup code signing in App Settings -> Code Signing.

Simply check-in a file called buddybuild_postbuild.sh as a peer file to your .xcodeproj or build.gradle files.

Environment Variables

Buddybuild exposes numerous environment variables that we've found to be helpful in the process of extending the build process to meet your needs. You can find the complete list in our documentation.

Examples

Below you'll find several examples of the ways that you can extend buddybuild. This is not a comprehensive list, just a few snippets of code that help illustrate some of the ways you can extend buddybuild to meet your specific needs.

Example 1: Conditionally uploading IPA/dSYMs to HockeyApp

The HockeyApp AppID is a string which was created when you added a new app to HockeyApp. To find your App ID, login to HockeyApp, click on your app's icon on the dashboard, then search for "App ID" in the info section (it should be right below your bundle identifier or package name).

Requests to HockeyApp that require authentication need to set the HTTP header X-HockeyAppToken to a valid API token. You can create and find your HockeyApp tokens under API Tokens in your HockeyApp account menu.

Contents of the buddybuild_postbuild.sh script:

#!/usr/bin/env bash

echo "Conditionally uploading IPAs and dSYMs to HockeyApp"

if [[ "$BUDDYBUILD_BRANCH" =~ "release" ]]; then  
  HOCKEYAPP_API_TOKEN=Your_API_token
  HOCKEYAPP_APP_ID=Your_AppID

  cd $BUDDYBUILD_PRODUCT_DIR
  find . -name "*.dSYM" -print | zip /tmp/dsyms.zip -@
  curl -v -F "ipa=@$BUDDYBUILD_IPA_PATH" \
          -F "dsym=@/tmp/dsyms.zip" \
          -H "X-HockeyAppToken: $HOCKEYAPP_API_TOKEN" \
       https://rink.hockeyapp.net/api/2/apps/$HOCKEYAPP_APP_ID/app_versions/upload
else  
    echo "This wasn't a release branch!"
fi  

Example 2: uploading dSYMs to Crashlytics

Fabric includes an upload-symbols script that you can call anywhere in your build process to upload your dSYMs. It’s included in Fabric CocoaPod payload at $PODS_ROOT/Fabric/upload-symbols.

Contents of the buddybuild_postbuild.sh script:

#!/usr/bin/env bash

echo "Uploading IPAs and dSYMs to Crashlytics"

CRASHLYTICS_API_KEY=Your_API_key  
echo "Uploading to Fabric via command line"  
$BUDDYBUILD_WORKSPACE/Pods/Fabric/upload-symbols -a $CRASHLYTICS_API_KEY -p ios $BUDDYBUILD_PRODUCT_DIR

Example 3: Installing and running SwiftLint

Swiftlint is a popular tool amongst iOS Swift developers used to enforce Swift style and conventions. This script will make sure that it's installed and run swiftlint before a build occurs.

Contents of the buddybuild_postclone.sh script:

#!/usr/bin/env bash

# Install swiftlint if necessary
if ! which swiftlint >/dev/null; then  
    brew install swiftlint
fi

# Run Swiftlint
echo "Here comes the output of Swiftlint"  
swiftlint  

Example 4: Adding values using PlistBuddy

PlistBuddy is used to read and modify values inside of a plist.

Contents of the buddybuild_prebuild.sh script:

#!/usr/bin/env bash
# Adding the buddybuild branch to a PList
/usr/libexec/PlistBuddy -c "Add APP_BRANCH String $BUDDYBUILD_BRANCH" "Info.plist"

Example 5: Installing a ruby gem

Installing a Ruby gem requires an elevation of privileges. That's simply done by sudo gem install {name_of_gem}.

To help illustrate the steps involved, the code below installs Slather — a tool used to generate test coverage reports for Xcode projects.

Contents of the buddybuild_postbuild.sh script:

#!/usr/bin/env bash

# Install Slather
sudo gem install slather

# Use Slather to generate test coverage
slather coverage -s --scheme name_of_your_scheme --build-directory $BUDDYBUILD_TEST_DIR/Build/Intermediates $BUDDYBUILD_WORKSPACE/name_ of_your_xcodeproject.xcodeproj  
Subscribe to receive other buddybuild updates.