Skip to content

Xcode Bot Triggers in Swift

I have recently started using Xcode Server to automate our builds which has led me to write pre and post integration triggers on my bots. I’ve previously written these scripts in Bash but have never taken any time to learn the language and haven’t had much exposure to Ruby either. It turns out that I’m not alone in this matter and can prove difficult when other developers have to understand and maintain the scripts in an unfamiliar language.

I was pretty excited when Swift was available for use on the command line. My first script was to automatically increment the build number based on the number of commits in my Git repository.

Here’s what it looks like:

  1. The first challenge was to access the XCS_SOURCE_DIR  environment variable. You can find a list of these variables hereNSProcessInfo  easily allows access to environment variables at runtime.
  2. Second I simply find the Info.plist file and parse it into a dictionary, change the CFBundleVersion , and write it back to the file. You’ll notice that this isn’t exactly the best way to write swift code but it’s ok, if it fails I want to know about it straight away.
  3. Third I had to use Git’s shell command to count the number of commits. I found some code to help me out here.
  4. Lastly I set the build number on the dictionary and write it back to disk.

So, a nice and easy way to set a build number on your release builds.

Published inContinuous IntegrationiOS

Be First to Comment

Leave a Reply