In last week’s blog post Andrew showed us how to trigger a build from another build. The need to do that was just the first part of a bigger series of events that eventually led to subsequent builds being automatically versioned for us.
After the builds were completed, we needed to ship the Xamarin.iOS build off to HockeyApp for distribution. These instructions made it an easy enough of a process and we got our first build from continuous integration (CI) pushed over.
However, problems arose when we wanted to push subsequent builds to HockeyApp. The app uploaded just fine but when we went in to manage it, we noticed that the version was exactly the same as the previous one. Of course none of the articles like this one described anything about updating version info as part of the CI process.
After doing a bit of research, I found a lot of people talking about a utility call Plistbuddy. I had no idea what that was or how to integrate that with my process because everyone was talking about it in reference to automating Xcode builds with TeamCity or Jenkins.
I knew that I could add another step to our build in VSTS but I wasn’t sure exactly how. So I just dove right in to see what kind of task I could come up with.
I knew that a PowerShell script wouldn’t do what I needed because I was running this with a local agent on a Mac, and Mac’s don’t do PowerShell. So I decided to grab the Shell Script task and see what it would allow me to do.
As you can see, options for setup on a shell scripts aren’t too plentiful:
I consulted some Microsoft-provided documentation and came up with this fairly simple script:
#!/bin/bash echo "setting versions to 1.0.$BUILD_BUILDID" export PLISTBUDDY="/usr/libexec/PlistBuddy" export INFO=$BUILD_SOURCESDIRECTORY"/AppName.Mobile/AppName.Mobile/AppName.Mobile.iOS/Info.plist" $PLISTBUDDY $INFO -c "set :CFBundleShortVersionString 1.0.$BUILD_BUILDID" $PLISTBUDDY $INFO -c "set :CFBundleVersion 1.0.$BUILD_BUILDID"
By running this as part of our build before the Xamarin.iOS build step we are ensured to get a unique build number. We can also update the VersionPatcher in different branches to get us new Major and Minor versions without having to change up our build process.
You can find out more about how Apple defines the CFBundlerShortVersionString and CFBundlerVersion to see how you need to update them for your apps.
Side note: I found this article from Microsoft that helped out immensely when trying to figure out how to do the App Signing and Provisioning profiles: https://msdn.microsoft.com/en-us/library/vs/alm/build/apps/secure-certs