27

I am setting up Jenkins for automating iOS builds. Are there any possibility to provide a .mobileprovision file that is not added to the provisioning tool in Xcode to xcodebuild?

I know that I can use PROVISIONING_PROFILE and PROVISIONING_PROFILE[sdk=iphoneos*] but they require the provisioning profile to be added to the Organizer.

I know that I can do the operation with xcrun. But before running xcrun I must successfully sign the app with xcodebuild.

Is there any way that I can just provide the provisioning profile file (.mobileprovision) to xcodebuild?

Fredrik Andersson
  • 3,567
  • 3
  • 19
  • 21

2 Answers2

49

We have a solution for this - essentially what you need to do is to 'install' the .mobileprovision file by copying it to a directory named after the UUID of the mobile provision file. This is what the Xcode Organizer actually does when you double-click a .mobileprovision file.

There's a little program called mpParse that can extract the UUID from the mobileprovision file that the script uses - link for download in the code. Then it's dead simple to copy the mobileprovision file to the correct place.

Here's a shell script I made to do this:

#!/bin/sh

# 2012 - Ben Clayton (benvium). Calvium Ltd
# Found at https://gist.github.com/2568707
#
# This script installs a .mobileprovision file without using Xcode. Unlike Xcode, it'll 
# work over SSH.
#
# Requires Mac OS X (I'm using 10.7 and Xcode 4.3.2)
#
# IMPORTANT NOTE: You need to download and install the mpParse executable from     http://idevblog.info/mobileprovision-files-structure-and-reading
# and place it in the same folder as this script for this to work.
#
# Usage installMobileProvisionFile.sh path/to/foobar.mobileprovision

if [ ! $# == 1 ]; then
 echo "Usage: $0 (path/to/mobileprovision)"
 exit
fi

mp=$1

uuid=`/usr/libexec/PlistBuddy -c 'Print UUID' /dev/stdin <<< $(security cms -D -i ${mp})`

echo "Found UUID $uuid"

output="~/Library/MobileDevice/Provisioning Profiles/$uuid.mobileprovision"

echo "copying to $output.."
cp "${mp}" "$output"

echo "done"

You can download the script direct from https://gist.github.com/2568707

Once you've run the script, you can use PROVISIONING_PROFILE and PROVISIONING_PROFILE[sdk=iphoneos*] in xcodebuild to create your app. We use this in production.

Edit: Just for reference, I asked essentially this question here a little while back ( Can an Xcode .mobileprovision file be 'installed' from the command line? ) and came up with the above when no-one seemed to know :-)

Update: As an alternative to mpParse one could use apple tools: /usr/libexec/PlistBuddy -c 'Print UUID' /dev/stdin <<< $(security cms -D -i path_to_mobileprovision)

Community
  • 1
  • 1
Ben Clayton
  • 80,996
  • 26
  • 120
  • 129
  • In case anyone needs this: The blog page for mpParse was down, but I was able to find the source and recompile it. I threw the compiled binary up at https://github.com/dwelch2344/mpParse/blob/master/build/mpParse - though you'll need to strip off the .txt that GitHub adds to the end – David Welch Oct 10 '13 at 16:18
  • 3
    Super helpful. Thanks so much. What I can't understand is that we were happily going along with xcodebuild for XCode4 using filenames of our own naming for PROVISIONING_PROFILE (e.g. PROVISIONING_PROFILE=EasyToRememberName), but this broke as described here with XCode5's version of xcodebuild. This information was invaluable at getting us unstuck. We still use easy-to-remember filenames, but we supply the UUID on the command line now. – tom d Dec 06 '13 at 21:23
  • You can file a bug report here: https://developer.apple.com/bug-reporting/ I can understand that you may feel that it will not be taken into account but the more feedback that we provide the better Xcode will get. – Gardner Bickford Mar 14 '14 at 21:06
  • 8
    Instead of using the `mpParse` third-party tool, you can use Apple's `security` and `PlistBuddy` tools – see [this answer](http://stackoverflow.com/a/10490095/1851186) – `/usr/libexec/PlistBuddy -c 'Print UUID' /dev/stdin <<< $(security cms -D -i path_to_mobileprovision)` – TachyonVortex Jun 20 '14 at 11:42
  • At least in Xcode 6 with Xcode Server 3.2.1 that seems to have changed. All you need to do is add your develop account credentials to Xcode Server. Please check out my answer and let me know if that is a solution: https://stackoverflow.com/a/25993995/300694 – vinzenzweber Sep 23 '14 at 11:36
0

If you use sigh from fastlane you can assign it's output to a variable provision_id=sigh

this also works if sigh has params: sigh(...)

This is the only script that worked for me:

`var=$(grep UUID -A1 -a | grep -io "[-A-Z0-9]{36}")'

use with: "$var.mobileprovision"

wolffan
  • 1,084
  • 10
  • 15