To make your build version management easy, Nevercode exports two environment variables that you can use in your build scripts:
NEVERCODE_BUILD_NUMBER. Read more about their meaning from here.
Build versioning in Cordova is as simple as defining a key in your configuration file
To set Android's
versionCode you'd have to define
android-versionCode and for iOS'
CFBundleVersion you'd have to define
ios-CFBundleVersion. Read more about it from the official documentation.
Here is an example of updating your build version using a simple
#!/usr/bin/env python import os import sys from xml.etree import ElementTree repo_path = os.getenv('NEVERCODE_BUILD_DIR') build_number = os.getenv('NEVERCODE_BUILD_NUMBER') if not build_number: print "Missing build number, skip updating" sys.exit() config_xml_path = os.path.join(repo_path, 'config.xml') ElementTree.register_namespace('', 'http://www.w3.org/ns/widgets') tree = ElementTree.parse(config_xml_path) root = tree.getroot() root.attrib['android-versionCode'] = build_number root.attrib['ios-CFBundleVersion'] = build_number tree.write(config_xml_path) print "Updated versionCode and CFBundleVersion to %s" % build_number
In order for Nevercode to run the above script during the build, it must have execute permission. Don't forget to run
chmod +x gh_update_cordova_version.py before committing and pushing your code.
To actually run the script you'd have to add the hook to your
<widget id="com.example.app" version="1.2.3" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> ... <hook type="before_prepare" src="gh_update_cordova_version.py" /> ... </widget>
Alternatively to hooks you can use custom build steps to bump the app version for CI builds.