How to Add Xcode Bot Integration Number Into Build Script

落花浮王杯 提交于 2019-12-20 09:58:11

问题


I'm creating an iPad application with a Settings.bundle file. I'm writing build scripts to display the application version number and the xcode bot integration number (not the bundle build number). I've searched the web and couldn't find any solution. Here's what I got yet:

-- Add the app version number
cd $PROJECT_DIR
cd "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app"

RELEASE_VERSION=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" Info.plist)
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:1:DefaultValue $RELEASE_VERSION" Settings.bundle/Root.plist

-- Add the build version number
BUILD_NUMBER=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" Info.plist)
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:2:DefaultValue $BUILD_NUMBER" Settings.bundle/Root.plist

In the build version number, I would like to replace the CFBundleVersion with the xcode bot Integration number.


回答1:


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.




回答2:


You actually don't even need agvtool to set the build number to the Xcode bot integration number. Simply set the Build number to ${XCS_INTEGRATION_NUMBER} in your project settings.




回答3:


I added (+) a Run Script to my targets Build Phase just prior to Compile Sources step. This one line script works for me to set the integration number as the build number. Thanks Kaelin, I just wanted to simplify things a little bit.

[ -z "$XCS_INTEGRATION_NUMBER" ] && echo "Build #0" || xcrun agvtool new-version ${XCS_INTEGRATION_NUMBER}



回答4:


I am setting this up with Xcode 10.1 on os 10.14.2, and found a couple of modifications were needed to make Kaelin's answer work. Here is my complete script:

#!/bin/sh
cd $XCS_PRIMARY_REPO_DIR
xcrun agvtool new-version -all "$XCS_BOT_NAME - Int. $XCS_INTEGRATION_NUMBER"

The mods are to change the directory (cd) to where the project lives when built. The other one is to add -all to the xcrun arguments.




回答5:


I stumbled over the same issue recently. There is a very pragmatic but ugly way of getting information about the latest integration number of Xcode Bots runs:

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'

I also created a stackoverflow question in order to find a more integrated and less hacky way of accomplishing this goal: Register for messages from collabd like XCSBuildService to receive Xcode Bots integration number

But maybe the way parsing the xcsbuildd.log as described above is sufficient for your purposes.



来源:https://stackoverflow.com/questions/22988378/how-to-add-xcode-bot-integration-number-into-build-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!