24

Current build script compiles the project and produces *.ipa, *.dsym and *.mobileprovision

1. Configure Mac slave computer (XCode should be already installed)

  • Set up RSA ssh authentication (out of scope)
  • Set up the node to look like this:
    Remote FS root = build directory on the Node
    Labels ? iPhone builds could be performed only on mac machines
    Host ? IP address of the mac machine
    Private Key File ? RSA key set up on the step a.

2. Copy build.sh script to the HOME directory of the Hudson user on the Node.

3. Configure new Hudson project:

  • Choice field: CONFIGURATION ? defines the configuration to build, must match configuration defined in xcode project

  • Execute Shell ? path to the build script on the Node. I also set up Hudson to poll SCM every 3 minutes for changes, this is VERY fast.

Notes:

  • Script always builds with the iPhone SDK 4.2 (on new SDK installation script have to be changed).
  • Certificate MUST be installed in keychain on the Node. "Access control" for the Private key in the Keychain MUST be set to "allow all applications to access this item"
  • XCode project file should be in the project root, if not ? set PROJDIR variable to the relative path to the folder with xcode project in build command.

Feedback welcome!

Proudly sponsored by http://www.arello-mobile.com

build.sh
#!/bin/sh

function fail {
    echo "$*" >&2
    exit 1
}

function section_print {
    echo "\n=== $* ==="
}

section_print "Building $CONFIGURATION";

if [ -z $CONFIGURATION ]; then
    fail "No configuration specified";
    exit 1;
fi

#strange way to force backslash
if [ $PROJDIR ]; then
    PROJDIR=${PROJDIR%/}
    PROJDIR="$PROJDIR/"

    section_print "Project Dir is specified and is $PROJDIR"
    cd "$PROJDIR" || fail "no directory $PROJDIR"
    pwd
fi

section_print "Unlocking keychain"
security unlock-keychain -p "password" ~/Library/Keychains/login.keychain

section_print "Cleaning build"
xcodebuild -configuration "$CONFIGURATION" clean || fail "Clean failed"

section_print "Building $CONFIGURATION"
xcodebuild -configuration "$CONFIGURATION" -sdk iphoneos4.2 || fail "Build failed"

section_print "Packaging ipa"

BUILD_PATH=build/"$CONFIGURATION"-iphoneos

#we are already in the $PROJDIR
cd "$BUILD_PATH" || fail "no directory 'build/$CONFIGURATION-iphoneos'"

for file in "*.app"
do
    APP_NAME=`echo $file`
done

APP_NAME=${APP_NAME%.*}

section_print "Removing old artefacts"
cd "$WORKSPACE"
rm -f *.ipa
rm -f *.dSYM.zip
rm -f *.mobileprovision

#take $PROJDIR into account
section_print "Application name $APP_NAME"
cd "$PROJDIR$BUILD_PATH"

rm -rf Payload
rm -f "$APP_NAME".*.ipa
mkdir Payload
cp -Rp "$APP_NAME.app" Payload/
if [ -f "$WORKSPACE"/iTunesArtwork ]; then
    cp -f "$WORKSPACE"/iTunesArtwork Payload/iTunesArtwork
fi

IPA_FILE="$APP_NAME.$BUILD_ID.$BUILD_NUMBER.ipa"
zip -r "$IPA_FILE" Payload

section_print "Compressing dSYM"
rm -f "*.dSYM.zip"
DSYM_FILE="$APP_NAME.$BUILD_ID.$BUILD_NUMBER.dSYM.zip"
zip -r "$DSYM_FILE" "$APP_NAME.app.dSYM"

section_print "Exporting profile"
cp -f "$APP_NAME.app/embedded.mobileprovision" profile.mobileprovision

section_print "Get the profile name"

PROFILE_NAME=`strings ./profile.mobileprovision | grep -A1 '<key>Name</key>' | tail -n1 | awk -F'<string>' '{print $2}' | awk -F'</string>' '{print $1}'`
PROFILE_NAME=${PROFILE_NAME//'*'/}
PROFILE_NAME=${PROFILE_NAME//'?'/}

PROFILE_NAME="$PROFILE_NAME.mobileprovision"

section_print "Profile name is $PROFILE_NAME"
mv -f "profile.mobileprovision" "$PROFILE_NAME"

rm -f "$WORKSPACE/*.mobileprobision" || fail "Failed to remove $WORKSPACE/*.mobileprovision"
rm -f "$WORKSPACE/$IPA_FILE" || fail "Failed to remove $WORKSPACE/$IPA_FILE"

section_print "Copying $IPA_FILE to artifacts"
cp -v "$IPA_FILE" "$WORKSPACE/." || fail "Failed to copy ipa"
cp -v "$PROFILE_NAME" "$WORKSPACE/." || fail "Failed to copy profile"
cp -v "$DSYM_FILE" "$WORKSPACE/." || fail "Failed to copy dSYM"

section_print "Build succeeded"

0

Is there any reason why you have not put the contents of build.sh directly into "Execute Shell" of Hudson?