Scripts we love – Xcode builds life savers

Don’t write long scripts on Jenkins or any other continuous integration system for your iOS builds. Xcode schemes give you lots of power to control your configurations and also give you space to write your project specific and scheme specific scripts. If you didn’t glance at my writings about build configurations and custom schemes. Check them out before continue reading: Build Configuration and Custom Schemes and Xcode Command Line Tools and Automated Builds

Screen Shot 2016-05-19 at 19.31.39
Select Scheme and Edit (Figure 1)

If you read previous articles on custom schemes, you’ve already realized that you don’t have to write scripts for all build variables. Special config files (.xcconfig extension files) do the duty for you.

But sometimes there may be some special actions you want to do, not only changing a variable’s value but also deleting files, definitions on special builds.

So, Build scripts are just for you! You can define pre-actions, post-actions for build, run, test, archive steps and so on…

Screen Shot 2016-05-19 at 22.39.44

Choose appropriate state for your script. For instance, if you want some changes before build starts, you should use pre-actions of Build step, or if you want to let test team know their application is ready, you can write your script at post-action section for Run step.

For creating Run Script Action, Select your scheme > Edit Scheme. (Figure 1)

After selecting action type and state at left navigation, you show click “+” button at the right bottom of scheme screen. (Figure 2)

Screen Shot 2016-05-19 at 22.40.08
Adding New Run Script Action – Figure 2

There are so many possible actions you can do with these actions : You can delete a file depending on a build configuration. You can read project variables and user defined variables which is defined in your project file. Configuration files give you flexibility about managing your build parameters in a clean way. Pre and post actions particularly gives you facility to manage other things which configuration files can’t do.

Tips and Tricks

Don’t use any unnecessary blank lines, it can corrupt your scripts for instance, if your set a variable in 1. line and 2.line is an extra blank line, your variable, let’s say x, it won’t be x, it will be x and line character. Be aware of it and count carefully  your script lines 😀

${SRCROOT} points the folder which contains your project’s xcodeproj.

You can reach your config name by using ${CONFIGURATION}

You can find any other default build variables for Xcode -> here.

I didn’t find out how watching the script logs on console. Xcode doesn’t show these kind of script information on it’s build console. Therefore, writing variable to file is  a good way to logging and checking whether your script is working or not. I know it’s old school. 🙂 It’s a clever way anyway.

echo $variable_name >> mylogfile.txt

May the Unix commands be with you.

PS: If you find this article useful please use like button:) and if you have a question or a comment, don’t hesitate to share it!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s