Changing Build Settings by code

One of the repetitive tasks I wish to avoid, is manually updating the version number in the build settings every time I build.

Is there a way to update this value by code?
I found PlayerSettings.bundleVersion, but not sure how to use it so it updates before each build. I wish to do something like:

static void CallMeBeforeBuild() {
	PlayerSettings.bundleVersion = MetaData.version; 
	// MetaData is my own static class

I also found the manual for post processing script, but I am not sure this is what I need.

You could do without scripting using the uTomate extension. With this you can set up an automation plan, where you first set up the player settings and then build your player(s). Then you can run the plan with a single click.