简体   繁体   English

如何将Xcode Bot集成号添加到构建脚本中

[英]How to Add Xcode Bot Integration Number Into Build Script

I'm creating an iPad application with a Settings.bundle file. 我正在创建一个带有Settings.bundle文件的iPad应用程序。 I'm writing build scripts to display the application version number and the xcode bot integration number (not the bundle build number). 我正在编写构建脚本来显示应用程序版本号和xcode bot集成号(而不是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. 在构建版本号中,我想用xcode bot集成号替换CFBundleVersion。

I implemented this using a Shell Script Build Phase in my Xcode project. 我在我的Xcode项目中使用Shell脚本构建阶段实现了这一点。 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. 请注意, Xcode服务器构建环境中默认存在XCS_INTEGRATION_NUMBER 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. 如果要模拟集成构建(出于此脚本的目的),您只需将其作为自定义变量添加到构建设置中。

You actually don't even need agvtool to set the build number to the Xcode bot integration number. 您实际上甚至不需要agvtool来将构建号设置为Xcode bot集成号。 Simply set the Build number to ${XCS_INTEGRATION_NUMBER} in your project settings. 只需在项目设置中将内部版本号设置为$ {XCS_INTEGRATION_NUMBER}即可。

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}

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. 我在os 10.14.2上使用Xcode 10.1进行设置,并发现需要进行一些修改才能使Kaelin的答案工作。 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. mods用于将目录(cd)更改为项目在构建时所处的位置。 The other one is to add -all to the xcrun arguments. 另一个是添加-all到xcrun参数。

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: 有一种非常实用但丑陋的方式来获取有关Xcode Bots运行的最新集成数量的信息:

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 我还创建了一个stackoverflow问题,以便找到一个更集成,更少hacky的方法来实现这个目标: 注册来自协作的消息,如XCSBuildService,以接收Xcode Bots集成号

But maybe the way parsing the xcsbuildd.log as described above is sufficient for your purposes. 但也许如上所述解析xcsbuildd.log的方式足以满足您的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM