3

During an Xcode Bots build each run gets an integration number assigned. This number does not show in the build logs but would be convenient to create http links back to the individual Xcode Bots build in an CI environment or enterprise app store.

In the /Library/Server/Xcode/Logs/xcsbuildd.log I found that XCSBuildService gets a message/event from collabd with a structure that contains the integration number.

Is there a way to register to the same event in an own (OSX) program and receive this message/event?


The only ugly way I found so far to get the Xcode Bots integration number was by parsing the xcsbuildd.log file with the drawback that I can't be sure that the latest integration number corresponds with my current build when several builds are executing in parallel. This log file is also located in an read protected folder/file so that I have to either change the permissions (ugh!) or use sudo (I don't really want to do that)!?

Example:

sudo grep -r "integration =" /Library/Server/Xcode/Logs/xcsbuildd.log | tail -1 | cut -d'=' -f 2| cut -d';' -f 1 |tr -d '\040\011\012\015'

Gives me the latest integration number stripped from whitespace ...

Edit: Just found out that if you actually include the following script in your scheme as Build-post-action it will create a file (e.g. /Library/Server/Xcode/Data/BotRuns/Cache/22016b1e-2f91-4757-b3b8-322233e87587/source/integration_number.txt) with the integration number without requiring sudo. Xcode Bots seems to serialize the different builds so that they are not executed in parallel and so the created integration number in the file could be used.

grep -r "integration =" /Library/Server/Xcode/Logs/xcsbuildd.log | tail -1 | cut -d'=' -f 2| cut -d';' -f 1 |tr -d '\040\011\012\015' >  ${PROJECT_DIR}/integration_number.txt
wfrank
  • 91
  • 7
  • You can clean this up a bit by using sed: `sed -E 's|.* ([0-9]+);|\1|'` will replace the cuts and tr, so the solution becomes `grep -r "integration =" /Library/Server/Xcode/Logs/xcsbuildd.log | tail -1 | sed -E 's|.* ([0-9]+);|\1|' > ${PROJECT_DIR}/integration_number.txt` – levigroker Jun 30 '14 at 20:43

1 Answers1

0

For specifically the case of getting the integration build number, I've added a simple answer here.

To repeat myself (and keep this from being down voted as a 1-line answer):


I implemented this using a Shell Script Build Phase in my Xcode project. In my case, I used the integration number to set the internal version of my built product. My script looks like this:

if [ "the$XCS_INTEGRATION_NUMBER" == "the" ]; then
    echo "Not an integration build…"
    xcrun agvtool new-version "10.13"
else
    echo "Setting integration build number: $XCS_INTEGRATION_NUMBER"
    xcrun agvtool new-version "$XCS_INTEGRATION_NUMBER"
fi

Note that XCS_INTEGRATION_NUMBER exists by default in the Xcode Server build environment. If you want to simulate an integration build (for the purposes of this script), you can simply add it to your build settings as a custom variable.

Community
  • 1
  • 1
Kaelin Colclasure
  • 3,925
  • 1
  • 26
  • 36