I want to create a version on a specific scan, the latest scan, and have it persist on that scan. I have a project where I created a version using the Sonarqube UI on the latest scan. On the next run of Sonarscan a new scan appears in the activity but the version I created that was on the previous scan now exists on the latest scan. The version name can be edited, but the version can not be deleted. Here are two sequential pictures showing what I mean. The only difference in these two pictures is Sonarscan ran on the project. I did not move the version myself. What am I doing wrong?
If you insist on keeping a version label for just that project scan/snapshot and persisting it, you can click on the gear icon next to the snapshot and click on “Create Version” (or “Create Custom Event”) to type in the version you want. The latest snapshot on November 19, 2020 9:08AM will propagate the 1.11.0-dev version with each subsequent snapshot. Here’s an example:
On November 19, 2020, 2:59 PM, I had the dont change me version snapshot, but at 3:00 PM the version continued forward. I then clicked on the gear icon on the 2:59 PM snapshot and manually added My First Version version label and created a custom event called 3rd scan. On the next 2 subsequent scans, the dont change me version label advanced for each snapshot.
@Joe, sorry for not replying sooner. I understand the behavior you described with the “don’t change me version” above, and that’s exactly what I don’t understand, or said differently don’t like.
Here’s a hypothetical use case:
We make our last change to a SW component
Our final build executes and runs Sonarscan
We see the new scan show up on the activity tab for the project
We see that this scan passed the quality gate
We decide this is the version we are going to publish
We click on the gear icon to create a “1.0” version on that latest scan.
We start work on 1.1.
We make a change/build/scan related to 1.1
I look at the activity for this project and now my 1.0 version is no longer on the original “1.0” scan. It is now on the latest scan and will continue to move forward to the latest each time a scan occurs. I now have lost my record of which scan was the 1.0 version.
This just seems counterintuitive to me, but it is exactly what you exemplified as expected behavior in your response, so what am I missing? It seems like you are saying I have to wait for my first “1.1” scan to complete, and then I can go back one scan and apply the “1.0” version to the previous scan, and then it will persist on that scan. That doesn’t make sense to me.
Apologies for this delayed answer. I see your problem now: the sonar.projectVersion is being used as a mark for confirming quality gate passing but subsequent scans are not setting it for the one you want.
Regarding your use case:
(Below are my opinions and thus perhaps not the best perspective, so take with a grain of salt.)
For your use case, I suggest you do not use the Activity UI to interact with the project version. The project version should ideally change from within your project, not the UI, since a project version typically follows the project lifecycle, not the Sonar scan history. See Analysis Parameters for other analysis parameters that can track a project’s lifetime.
So that means, at the bold step above (“We make a change/build/scan related to 1.1”), you should add the Sonar analysis parameter sonar.projectVersion=1.1 so that the New Code Period can use 1.0 project version as the one to compare 1.1 project version to. Please read our New Code Period documentation for more details on this setting. By default, we use “Previous Version” globally and “Previous Version” at the project level.
I believe you wanted to establish a project version with a passing quality gate, but the project itself doesn’t get this feedback and can’t keep track of this history, so each subsequent Sonar scan progresses forward. Project version should be defined as the project’s state, not Sonar scan state.
Thus, the only time you should modify anything on the Activity UI:
Adding a custom event (like a special comment or annotation to underscore the Sonar scan result)
Correcting a project version mistake
You should not interact with this screen otherwise if you ensure that project version is defined by each Sonar scan, which can easily be done with sonar-project.properties or at the sonar-scanner command line or the like.
As an alternative, in SonarQube 8.6 at least, you can choose various New Code Periods:
Specific analysis (available at branch level in Developer Edition and higher, otherwise project level for Community Edition)
Number of days
The “Specific analysis” option might work for you too, so you can test this one out, if you don’t intent on changing your current workflow.
To get to that option, go to the project dashboard > Project Settings > New Code. Then click on the gear icon on the far right-hand side of the branch of interest. Click Edit. Then select which method of analysis for New Code Period you want.