在构建阶段中是否有自动将自定义值写入捆绑包的.plist文件的方法?

4
我正在使用Jenkins搭建一个CI系统,并在构建时使用agvtool来升级和设置营销和技术版本。除了在构建时设置版本号外,还希望能在.plist文件中设置一些自定义值,这是否可行?

你好,你能帮我解决这个问题吗?我想从Jenkins向Xcode发送一些自定义参数。 - Shruti
1个回答

10
你可以利用“预操作”选项运行脚本,在构建时编辑Info.plist。

enter image description here

这是一个示例脚本,用于增加 Plist 中名为 UserDefinedVersionNumber 的键的值。
#!/bin/sh

#Grabs info from plist
plist=$SRCROOT"/"$INFOPLIST_FILE
currentBuild=`/usr/libexec/PlistBuddy -c "Print :UserDefinedVersionNumber" "$plist"`

#And changes it before writing out the plist again
if [ -z "$currentBuild" ]
then
    currentBuild=1
    /usr/libexec/PlistBuddy -c "Add :UserDefinedVersionNumber string $currentBuild" "$plist"

else
    currentBuild=$(($currentBuild + 1));
    /usr/libexec/PlistBuddy -c "Set :UserDefinedVersionNumber $currentBuild" "$plist"
fi

你应该能够直接在那个小框中输入脚本,但我发现编辑和维护它可能会变得麻烦,特别是对于共享的脚本。

谢谢,有用的信息。是否有任何方法可以使用构建系统中的值来完成这种操作,例如假设Jenkins在构建之前或构建时获取某个数字,我想将其注入到bundle info.plist中。使用此方案,XCode需要获得/访问该数字。 - Gruntcakes
我不知道Jenkins是什么,所以不能确定,但所有的构建设置都通过“从...提供构建设置”位向脚本提供。 - James Webster
如果在Jenkins中,您可以使用预构建shell脚本来使用plist buddy修改plist文件。我们使用它将git修订哈希放入构建中,以便QA更轻松地确定他们正在测试的构建版本。 - jpancoast

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接