# Automatic build numbering

**URL:** <https://forum.ionicframework.com/t/automatic-build-numbering/9283>\
**Category:** ionic-v1\
**Created:** [September 7, 2014, 11:55pm UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283 "2014-09-07T23:55:57Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evanion](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/evanion/32/65957_2.png) [@Evanion](https://forum.ionicframework.com/u/Evanion)\
**Post date:** [September 7, 2014, 11:55pm UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/1 "2014-09-07T23:55:57Z")

</div>

Anyone know of any hook that automatically updates the build numbering when building?  
I’m keep forgetting to doing it manually (and it’s unnecessarily time-consuming)  
I’m not looking for a automatic version updater, as that would just cause problems, but a automatic build updater, would help when releasing new beta builds, and fix statistic tracking in for instance hockeyapp.

---

<div class="post-metadata">

**Author:** ![epelc](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@epelc](https://forum.ionicframework.com/u/epelc)\
**Post date:** [September 8, 2014, 1:07am UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/2 "2014-09-08T01:07:47Z")

</div>

You could make a `before_build` hook to change your app version in config.xml or make it stick a build number in your html/js. There are several more hooks that you might want to use instead but you can write them all in nodejs. Checkout the docs on [github](https://github.com/apache/cordova-lib/blob/master/cordova-lib/templates/hooks-README.md) for cordova cli hooks if you want more info. There is also a nice [article](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/) about some basic but useful hooks that should help you get started.

Also if you get a build hook working to increment the build number somewhere please share it as I would also find this useful.

---

<div class="post-metadata">

**Author:** ![Evanion](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/evanion/32/65957_2.png) [@Evanion](https://forum.ionicframework.com/u/Evanion)\
**Post date:** [September 8, 2014, 7:51am UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/3 "2014-09-08T07:51:53Z")

</div>

Yea, I have already implemented that article… it’s great.  
I wish there was a hook database where you could easily search for useful hooks. Googling for them is a pain!

I will take another cack on using the replace\_text hook.

---

<div class="post-metadata">

**Author:** ![Evanion](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/evanion/32/65957_2.png) [@Evanion](https://forum.ionicframework.com/u/Evanion)\
**Post date:** [September 8, 2014, 9:41am UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/4 "2014-09-08T09:41:12Z")

</div>

Ok, I have a semi dirty version working based on the ‘replace text’ hook.  
I have made a [gist](https://gist.github.com/Evanion/be750c2445416dd4f91a) of the hook.  
Right now it only suffixes the build number to the version number. I would like to in the future separate it out to a separate ‘build’ metadata, that will be read correctly by Hockeyapp.

---

<div class="post-metadata">

**Author:** ![Evanion](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/evanion/32/65957_2.png) [@Evanion](https://forum.ionicframework.com/u/Evanion)\
**Post date:** [September 8, 2014, 11:25am UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/5 "2014-09-08T11:25:39Z")

</div>

Updated gist with bugfix.

---

<div class="post-metadata">

**Author:** ![epelc](https://avatars.discourse-cdn.com/v4/letter/e/4bbf92/32.png) [@epelc](https://forum.ionicframework.com/u/epelc)\
**Post date:** [September 9, 2014, 12:21am UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/6 "2014-09-09T00:21:41Z")

</div>

Thanks for that. I think it might be nicer if you made it replace the build number in a config.js so you could access it while the app is running easily. Looks like all you have to do is change the file path and it should work. This seems easier then trying to make it a separate ‘build’ metadata. I already have a config.js which I store my apiUrl in as mentioned earlier so the javascript approach works nicely for me.

If you don’t like this idea are there any benefits to it being in config.xml instead of your javascript? Is there a way you could access it from the config.xml while running to display it nicely for instance on a settings page? Also I don’t know if the build number being appended to the version number will work nicely with google play or the app store haven’t tried it though.

---

<div class="post-metadata">

**Author:** ![Evanion](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/evanion/32/65957_2.png) [@Evanion](https://forum.ionicframework.com/u/Evanion)\
**Post date:** [September 9, 2014, 8:56am UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/7 "2014-09-09T08:56:14Z")

</div>

You could definitely update a js file as well.  
All you need to do is add the path to the build files array, and include the ‘BUILDNR’ placeholder where you want the build number to be included.

When working with version and build numbers, they are usually handled separately. One is used to track releases (version numbers), and the other to track development versions (build).

We use hockeyApp to distribute our beta version, and they let us breakdown statistics and reports by version and build.

If you want to make it simple, you can always append the buildnr with a dot instead of a dash:  
1.0.0.1056  
Where the build number is the last quintet. But yes, the plan is to move the buildnumber away from the version number all together.

The reason for using the config.xml file, is because that’s where ionic/cordova retrives the info when including it in all the system files for the different platforms.

---

<div class="post-metadata">

**Author:** ![emaV](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@emaV](https://forum.ionicframework.com/u/emaV)\
**Post date:** [October 7, 2014, 2:13pm UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/8 "2014-10-07T14:13:13Z")

</div>

`#onlyfornoobslikeme` - Remember to create the `build.json` in the `resources` directory…

---

<div class="post-metadata">

**Author:** ![Evanion](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/evanion/32/65957_2.png) [@Evanion](https://forum.ionicframework.com/u/Evanion)\
**Post date:** [October 7, 2014, 4:19pm UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/9 "2014-10-07T16:19:28Z")

</div>

[update]  
If you want to separate the build number from the version number, you can add the following to the tag in your config.xml:

```
version="VERSIONNR" android-versionCode="BUILDNR" ios-CFBundleVersion="BUILDNR"

```

so it looks something like this:

```
<widget id="APPID" version="VERSIONNR" android-versionCode="BUILDNR" ios-CFBundleVersion="BUILDNR" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

```

(text in uppercase are placeholders)

---

<div class="post-metadata">

**Author:** ![jlinoff](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@jlinoff](https://forum.ionicframework.com/u/jlinoff)\
**Post date:** [November 24, 2014, 8:04pm UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/10 "2014-11-24T20:04:26Z")

</div>

Thank you. I also found this to be very helpful.

---

<div class="post-metadata">

**Author:** ![ohh2ahh](https://avatars.discourse-cdn.com/v4/letter/o/779978/32.png) [@ohh2ahh](https://forum.ionicframework.com/u/ohh2ahh)\
**Post date:** [June 1, 2015, 5:55pm UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/11 "2015-06-01T17:55:33Z")

</div>

I’ve just created my very first hook, which increments the build numbers directly in the project’s `config.xml`. Here’s a gist if anyone is interested.

> <https://gist.github.com/ohh2ahh/f35ff6e0d9f8b4268cdb>

---

<div class="post-metadata">

**Author:** ![Evanion](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/evanion/32/65957_2.png) [@Evanion](https://forum.ionicframework.com/u/Evanion)\
**Post date:** [July 7, 2015, 7:06pm UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/12 "2015-07-07T19:06:13Z")

</div>

Looks a lot smoother than my approach. I will definitely try it out on my next app.

---

<div class="post-metadata">

**Author:** ![danp](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@danp](https://forum.ionicframework.com/u/danp)\
**Post date:** [September 23, 2015, 2:19pm UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/13 "2015-09-23T14:19:30Z")

</div>

Great hook.  
If anyone want’s to update the “version” part (the one that looks like 0.1.2), you can add this to the js code:

```
// Get the version string (format is x.y.z) and split it to its components
var currentVersion = obj['widget']['$']['version'];
var currentVersionComponents = currentVersion.split(".");

// Increment the z value
currentVersionComponents[2]++;

// rebuild the version string, and set it on the object
var newVersion = currentVersionComponents[0] + "." + currentVersionComponents[1] + "." + currentVersionComponents[2];
obj['widget']['$']['version'] = newVersion;
```

---

<div class="post-metadata">

**Author:** ![HenryL](https://avatars.discourse-cdn.com/v4/letter/h/b5e925/32.png) [@HenryL](https://forum.ionicframework.com/u/HenryL)\
**Post date:** [October 31, 2015, 3:15pm UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/14 "2015-10-31T15:15:18Z")

</div>

Excellent work ! Thanks for saving me time

---

<div class="post-metadata">

**Author:** ![mix3d](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@mix3d](https://forum.ionicframework.com/u/mix3d)\
**Post date:** [March 29, 2016, 5:50pm UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/15 "2016-03-29T17:50:52Z")

</div>

Old thread, but there is a cordova plugin that can work just as well here: [https://www.npmjs.com/package/cordova-build-increment](https://www.npmjs.com/package/cordova-build-increment)

It will read your config.xml for android-versionCode and ios-CFBundleVersion, and auto increment them after each build, and can be set to only increment on --release versions, not debug builds.

---

<div class="post-metadata">

**Author:** ![pedrobrasileiro](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pedrobrasileiro/32/92598_2.png) [@pedrobrasileiro](https://forum.ionicframework.com/u/pedrobrasileiro)\
**Post date:** [June 18, 2017, 9:14pm UTC](https://forum.ionicframework.com/t/automatic-build-numbering/9283/16 "2017-06-18T21:14:45Z")

</div>

dont work from me

config.xml build numbers not changed

after 5 builds
