# How do you handle version and build numbers?

**URL:** <https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274>\
**Category:** ionic-v3\
**Created:** [August 17, 2017, 7:36am UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274 "2017-08-17T07:36:43Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Audrey84](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/audrey84/32/111010_2.png) [@Audrey84](https://forum.ionicframework.com/u/Audrey84)\
**Post date:** [August 17, 2017, 7:36am UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/1 "2017-08-17T07:36:43Z")

</div>

As I understand it, I can set a `version` in `<widget>` of `config.xml`. Then when I build my project, Cordova somehow generated “build numbers” out of that.

But each build for a `version` seems to get the same build number (iOS identical to the version, for Android the `versionCode` is some math calculated out of the major.minor.patch =\> major0minor0patch), so not very useful.

There also seem to be iOS and Android specific “build numbers” I can set in `config.xml`: `android-versionCode` and `ios-CFBundleVersion`. But then I have to manage these myself, similar to the `version`.

How do you handle version and build numbers?  
Do you have the same build numbers on iOS and Android?  
How do you handle builds of Ionic? Does it also have a version number somehow?

---

<div class="post-metadata">

**Author:** ![mburger81](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mburger81](https://forum.ionicframework.com/u/mburger81)\
**Post date:** [September 15, 2017, 8:50am UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/2 "2017-09-15T08:50:38Z")

</div>

Hi did you found a solution for this? There are hooks and something like that, in the hook we can override the build number manually but we are searching for a parameterized variables like that  
version="$VERSION\_NUMBER", and on the hook we can change the parameter reading from another configuration file.

Can you help?

---

<div class="post-metadata">

**Author:** ![Audrey84](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/audrey84/32/111010_2.png) [@Audrey84](https://forum.ionicframework.com/u/Audrey84)\
**Post date:** [September 15, 2017, 9:11am UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/3 "2017-09-15T09:11:42Z")

</div>

No, as I do not understand what you are asking me.

I right now manually increment the android-versionCode and ios-CFBundleVersion in config.xml for each build where the build number is relevant.

---

<div class="post-metadata">

**Author:** ![mburger81](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mburger81](https://forum.ionicframework.com/u/mburger81)\
**Post date:** [September 15, 2017, 2:27pm UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/4 "2017-09-15T14:27:03Z")

</div>

My intention was, on every production build I would like to increment an iterator an variable, and this variable I would like to use in my config.xml. I’m not sure if there is a possibility to use VARIABLES in config.xml and cordova builds?

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [September 15, 2017, 2:38pm UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/5 "2017-09-15T14:38:45Z")

</div>

This sounds like a problem for a build script or process modification.

#1 In Cordova world hooks exist, #2 in Ionic world you can modify what script is executed by modifying the `scripts` portion of your package.json. #3 If you use a CI service, that can probably also doe things before actually calling `ionic cordova build`.

---

<div class="post-metadata">

**Author:** ![mburger81](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mburger81](https://forum.ionicframework.com/u/mburger81)\
**Post date:** [September 15, 2017, 4:01pm UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/6 "2017-09-15T16:01:40Z")

</div>

> [@Sujan12](#):
>
> world

Yes I saw the hooks and there I can run a javascript which is reading changing config.xml file and set version number.  
But probably this all is a little bit to complicate and probably it is better handle the version number by hand.

We have to synchronize the [sentry.io](http://sentry.io) RELEASE number with the cordova VERSION, doing this manually often is something anybody probably forget. But setting an automatic version number not a build number is perhaps also not a good idea.

---

<div class="post-metadata">

**Author:** ![QGangler](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/qgangler/32/113105_2.png) [@QGangler](https://forum.ionicframework.com/u/QGangler)\
**Post date:** [September 15, 2017, 4:25pm UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/7 "2017-09-15T16:25:51Z")

</div>

> [@Audrey84](#):
>
> How do you handle version and build numbers?

On my CI process (I use [fastlane](https://fastlane.tools/)) I base everything on the `ios-CFBundleVersion` in the `config.xml`.

I have it formatted like this: `MAJOR.MINOR.PATCH.BUILD` (ex: 1.1.0.2)

After changing the `ios-CFBundleVersion` you can remove the last number to set the `version` attribute like this: `MAJOR.MINOR.PATCH` (ex: 1.1.0)

And calculate the `android-versionCode` attribute from the `ios-CFBundleVersion`:  
`MAJOR * 100000000 + MINOR * 100000 + PATCH * 1000 + BUILD`

I use a custom fastlane lane to open the `config.xml` file and change the values (you can do this using gulp or a npm script)

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [September 15, 2017, 4:44pm UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/8 "2017-09-15T16:44:59Z")

</div>

> [@mburger81](#):
>
> Yes I saw the hooks and there I can run a javascript which is reading changing config.xml file and set version number.
> 
> But probably this all is a little bit to complicate and probably it is better handle the version number by hand.

No, that is actually absolutely what they should be used for.

> [@mburger81](#):
>
> We have to synchronize the [sentry.io](http://sentry.io) RELEASE number with the cordova VERSION, doing this manually often is something anybody probably forget. But setting an automatic version number not a build number is perhaps also not a good idea.

Same here - I imagine Sentry has an API one can call with a new deploy/release or even by setting the value directly in the code.

---

<div class="post-metadata">

**Author:** ![mburger81](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mburger81](https://forum.ionicframework.com/u/mburger81)\
**Post date:** [October 5, 2017, 3:34pm UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/9 "2017-10-05T15:34:04Z")

</div>

Great, can you share more information on how you integrate fastlane? It sounds good!

---

<div class="post-metadata">

**Author:** ![QGangler](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/qgangler/32/113105_2.png) [@QGangler](https://forum.ionicframework.com/u/QGangler)\
**Post date:** [October 5, 2017, 3:48pm UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/10 "2017-10-05T15:48:53Z")

</div>

I know @Sujan12 is working on a tutorial to integrate fastlane with ionic on [ionic.zone](https://ionic.zone/fastlane).

I followed the [tutorial of fastlane](https://docs.fastlane.tools/getting-started/ios/setup/) and used the [cordova plugin](https://github.com/bamlab/fastlane-plugin-cordova) for it.  
The only custom piece of code I wrote was for changing the version number as described in my previous post (I used the gem nokogiri to modify `config.xml`).

---

<div class="post-metadata">

**Author:** ![raschidjfr](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/raschidjfr/32/137849_2.png) [@raschidjfr](https://forum.ionicframework.com/u/raschidjfr)\
**Post date:** [April 26, 2018, 7:30pm UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/11 "2018-04-26T19:30:05Z")

</div>

Just copy this file into `hooks` folder and that’s it. You can customize it to your needs.  
(need to npm install xml2js)

> <https://gist.github.com/RaschidGithub/636aac1841fdc2dbc2407cfc9d57df4c>

---

<div class="post-metadata">

**Author:** ![raschidjfr](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/raschidjfr/32/137849_2.png) [@raschidjfr](https://forum.ionicframework.com/u/raschidjfr)\
**Post date:** [January 20, 2020, 7:35pm UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/12 "2020-01-20T19:35:34Z")

</div>

**EDIT:** I’m updating this link as I changed my githubname: [https://gist.github.com/raschidjfr/636aac1841fdc2dbc2407cfc9d57df4c](https://gist.github.com/raschidjfr/636aac1841fdc2dbc2407cfc9d57df4c)

---

<div class="post-metadata">

**Author:** ![Fuggy](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Fuggy](https://forum.ionicframework.com/u/Fuggy)\
**Post date:** [April 18, 2020, 7:48am UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/13 "2020-04-18T07:48:39Z")

</div>

I’m using bump ([https://www.npmjs.com/package/@fabiospampinato/bump](https://www.npmjs.com/package/@fabiospampinato/bump)) and cordova-set-version ([https://www.npmjs.com/package/cordova-set-version](https://www.npmjs.com/package/cordova-set-version)). I created a node script to have versionnumbers of package.json and config.xml in sync:

scripts/version\_config\_xml.js

```auto
#!/usr/bin/env node
const cordovaSetVersion = require('cordova-set-version');
cordovaSetVersion();

```

then I ran:

```auto
bump patch --postbump "node scripts/version_config_xml.js"

```

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:01pm UTC](https://forum.ionicframework.com/t/how-do-you-handle-version-and-build-numbers/102274/14 "2021-07-19T21:01:12Z")

</div>

Closed on July 19, 2021, 9:01pm UTC


