# Set bitrise build number during build

**URL:** https://discuss.bitrise.io/t/set-bitrise-build-number-during-build/8574
**Category:** Question & Answer
**Created:** [March 27, 2019, 12:07pm UTC](https://discuss.bitrise.io/t/set-bitrise-build-number-during-build/8574 "2019-03-27T12:07:01Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![jzeferino](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/jzeferino/32/2159_2.png) [@jzeferino](https://discuss.bitrise.io/u/jzeferino)
#### Post date: [March 27, 2019, 12:07pm UTC](https://discuss.bitrise.io/t/set-bitrise-build-number-during-build/8574/1 "2019-03-27T12:07:01Z")

</div>

I’m trying to set the `BITRISE_BUILD_NUMBER` during the build process.

My .yml have two scripts:

1 - that sets the `BITRISE_BUILD_NUMBER` via `envman add --key BITRISE_BUILD_NUMBER --value 31`

I was expecting that after the build end, the number of the build is 31, but it uses the incremental number from the previous build.

Any feedback on this?

---

<div class="post-metadata">

### Author: ![fehersanyi-bitrise](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/fehersanyi-bitrise/32/1912_2.png) [@fehersanyi-bitrise](https://discuss.bitrise.io/u/fehersanyi-bitrise)
#### Post date: [March 27, 2019, 1:47pm UTC](https://discuss.bitrise.io/t/set-bitrise-build-number-during-build/8574/2 "2019-03-27T13:47:57Z")

</div>

Hy there, the build number will not change like this, if you want to use the build number for somthing then use it as a base that you modify, like  
`envman add --key my-build-num --value ($BITRISE_BUILD_NUMBER-43)`  
I would say

---

<div class="post-metadata">

### Author: ![jzeferino](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/jzeferino/32/2159_2.png) [@jzeferino](https://discuss.bitrise.io/u/jzeferino)
#### Post date: [March 27, 2019, 2:09pm UTC](https://discuss.bitrise.io/t/set-bitrise-build-number-during-build/8574/3 "2019-03-27T14:09:32Z")

</div>

Hello, I know that, but what I need is to set the build number in bitrise with the version I want.

---

<div class="post-metadata">

### Author: ![fehersanyi-bitrise](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/fehersanyi-bitrise/32/1912_2.png) [@fehersanyi-bitrise](https://discuss.bitrise.io/u/fehersanyi-bitrise)
#### Post date: [March 27, 2019, 2:19pm UTC](https://discuss.bitrise.io/t/set-bitrise-build-number-during-build/8574/4 "2019-03-27T14:19:16Z")

</div>

could you check this guide out? -\> [https://devcenter.bitrise.io/builds/build-numbering-and-app-versioning/](https://devcenter.bitrise.io/builds/build-numbering-and-app-versioning/)

---

<div class="post-metadata">

### Author: ![jzeferino](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/jzeferino/32/2159_2.png) [@jzeferino](https://discuss.bitrise.io/u/jzeferino)
#### Post date: [March 27, 2019, 2:23pm UTC](https://discuss.bitrise.io/t/set-bitrise-build-number-during-build/8574/5 "2019-03-27T14:23:26Z")

</div>

I already did that. I want to specify the number of the build from my build script.

---

<div class="post-metadata">

### Author: ![fehersanyi-bitrise](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/fehersanyi-bitrise/32/1912_2.png) [@fehersanyi-bitrise](https://discuss.bitrise.io/u/fehersanyi-bitrise)
#### Post date: [March 27, 2019, 2:27pm UTC](https://discuss.bitrise.io/t/set-bitrise-build-number-during-build/8574/6 "2019-03-27T14:27:53Z")

</div>

You could try this script then,  
make sure to add `$BITRISE_SOURCE_DIR/magicnum.txt` to the cache push step

```auto
#!/usr/bin/env bash
# fail if any commands fails
set -e
# debug log
set -x

if [! -f $BITRISE_SOURCE_DIR/magicnum.txt]
then
  touch $BITRISE_SOURCE_DIR/magicnum.txt
fi

inc=$(<$BITRISE_SOURCE_DIR/magicnum.txt)
if [-z "$inc"]
then
  echo 1000 > $BITRISE_SOURCE_DIR/magicnum.txt
  inc=$(<$BITRISE_SOURCE_DIR/magicnum.txt)
fi

if [$BITRISE_TRIGGERED_WORKFLOW_TITLE == "test"]
then
  build_number_offset=1
  envman add --key MY_BUILD_NUMBER --value $((build_number_offset + inc))
  echo $(( inc + 1 )) > ./magicnum.txt
fi

```

obviously, don’t use 1000 but the number you want

---

<div class="post-metadata">

### Author: ![jzeferino](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/jzeferino/32/2159_2.png) [@jzeferino](https://discuss.bitrise.io/u/jzeferino)
#### Post date: [March 27, 2019, 3:01pm UTC](https://discuss.bitrise.io/t/set-bitrise-build-number-during-build/8574/7 "2019-03-27T15:01:07Z")

</div>

Not sure if this does what I need.

I need to change the `#2` to a custom value (ex: `1.1.1`) from the build script. Is this possible?

![35](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/d/dc1ecd636c05d4a9b146ae329b5844b8b518e697.png)

---

<div class="post-metadata">

### Author: ![fehersanyi-bitrise](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/fehersanyi-bitrise/32/1912_2.png) [@fehersanyi-bitrise](https://discuss.bitrise.io/u/fehersanyi-bitrise)
#### Post date: [March 27, 2019, 3:23pm UTC](https://discuss.bitrise.io/t/set-bitrise-build-number-during-build/8574/8 "2019-03-27T15:23:19Z")

</div>

no, that you can not do, but you could create a feature request on it here: [http://discuss.bitrise.io/c/feature-request](http://discuss.bitrise.io/c/feature-request)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/d/d901cf2aad020f2dd11918afc89ec2089bb87b35.png) [@system](https://discuss.bitrise.io/u/system)
#### Post date: [April 26, 2019, 3:23pm UTC](https://discuss.bitrise.io/t/set-bitrise-build-number-during-build/8574/9 "2019-04-26T15:23:25Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
