How to set a specific previous version (for new code) based on branch name

Template for a good new topic, formatted with Markdown:

  • ALM used: GitHub
  • CI system used: Google cloud
  • Languages of the repository: Javascript - typescript


Hope you are doing great1

So I have a project with 3 different environments: dev, staging and production.
For each of these environments, we have a branch on github.
Whenever we want to add a new feature, we start by creating a new branch where we do all the code and once it’s reviewed, we merge it to to the dev branch, and then to the staging branch and finally to production.

So this is the workflow we follow at my company.

Now here is my need:

I have created new quality gates where I added conditions on new code like for example on coverage.
The New Code for new projects will be based on: Previous version.

How can I make sure when creating a new branch, that the previous version is:
- The last commit on the branch dev when on a feature branch
- The last commit on the branch staging when merging on staging
- The last commit on the branch production when merging on production

What is the command that I have to add?

Thank you in advance,

In some other ticket, I saw that I can do this using sonar.version but I don’t know what’s the value I have to set for this variable if it’s the correct thing to do.


Do you really want to reset the New Code Period for each commit?

If so (it’s not what we typically recommend) just pass your build number in to sonar.projectVersion.


I want to set the previous version to the latest commit I have on dev/staging/production.
I don’t know if this means that I have to reset the New code period.

And if this is the case, this means that I have to change the build number each time I do a push on the dev branch or on the staging or production branch?
Can’t I do it just by basing my work on the name of the branch?


You want the New Code Period for dev to be based on the differences versus staging? Theoretically you could set the New Code Period to use staging as a reference brance. However, since your changes flow in the other direction (staging rebased from dev rather than the other way around) I’m not confident this will work the way you want it to.

For your feature branches though, it should absolutely work to set the New Code Period to use dev as a reference branch.