Best approach to updating app version after build?

I’m trying to find the best approach to updating the version for my application after a build happens. I have a .NETCore application with a Version.json file that looks like this:

{
“Major”: 0,
“Minor”: 0
}

In my Jenkinsfile, after the build happens I have a stage that calls a bash script that will update the version, so after it would look like

{
“Major”: 0,
“Minor”: 1
}

The idea is then to have another bash script to git commit this and push it up to my branch (I haven’t gotten this far yet). I was wondering if this seems like a good approach to handle versioning? Or, if anyone does it another way and has suggestions(I want this to be automatic and handled through Jenkins, I don’t want to do it manually).

Thanks.

Another way is to generate the minor version number from the Git history. For example, run git describe or git rev-list --count HEAD, and capture the output. Or even use Nerdbank.GitVersioning. If you do one of these, then the automation won’t need to push the version numbers back to the repository, and the developers won’t need to merge those changes. On the other hand, the generated version numbers might increase faster than you’d like.

I’m actually running into an issue with the approach in the OP. I have a final stage where I update the version, git commit and git push. This does update the version, except it starts an infinite build loop, as my git push triggers another build, and on and on.

Is there any way to do this successfully? I’m using a Pipeline, btw.

Thanks.

A little hacky, but https://plugins.jenkins.io/scmskip/ could do it.

1 Like

Hello @joeyb1648 and welcome to this community :wave:
Are you sure you only want to change the minor version within your file?
Wouldn’t you want to also tag your commit with this version in git so that you can easily find it later on?