4

I'm setting up a CI system using Jenkins and am using agvtool to bump and set marketing & technical versions at build time.

In addition to setting the versioning at build time it would be very useful to set a couple of of custom values in the .plist.

Is this possible?

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • Hi can you help me out on this. From Jenkins I want to send some custom parameters to Xcode. – Shruti Jan 29 '21 at 10:49

1 Answers1

10

You can edit the Info.plist at build time by taking advantage of the "Pre-actions" options to run a script.

enter image description here

Here's an example script that increments a Key in the Plist called 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

You should be able to type the script directly into that little box, but I find that editing and maintaining it can become troublesome, especially for shared scripts.

James Webster
  • 31,873
  • 11
  • 70
  • 114
  • Thanks, useful info. Is there anyway of doing this sort of thing but with the values coming from the build system, i.e. suppose Jenkins grabs some number prior to or at build time and I want to inject that into the bundle info.plist. With this scheme XCode needs to have/get access to that number. – Gruntcakes Dec 03 '12 at 19:45
  • I don't know what Jenkins is so I can't say for certain, but all of the build settings are provided to the script via the "Provide build settings from..." bit. – James Webster Dec 03 '12 at 19:47
  • If in Jenkins, you can use a use a prebuild shell script to modify a plist file using plist buddy. We use it to put the git revision hash into the build to make it easier for QA to determine which version of the build they're testing. – jpancoast Dec 04 '12 at 17:07