Issue Synchronization between Branches

Versions:

  • SonarQube Enterprise V9.9.4 LTS
  • sonar-scanner-5.0.1.3006-windows

I’m testing synchronization of issues between branches as described in the documentation (Branch analysis / Issue Creation and Synchronization). My test project has the master (MAIN Branch) and a feature branch. The feature branch’s new code definition is “reference branch: master”.

First I tested synchronization of security hotspot review and this worked fine. The review comments I made on the feature branch were copied to the master branch when I performed a scan on this.

Then I wanted to test the synchronization of issue attributes. For this I added some new source code bringing me three new issues in the feature branch. On two of these I modified their attributes (comment, assigned to, resolution, severity), the third I left unchanged. Then I performed a new scan of the updated source code on the master branch, just like with a merge.

After that the three new issues appeared in the master branch, too, but the modifications on the attributes I did on the feature branch before were not synchronized to the master branch. In the change log of those two issues it just says “Created at …” (like with completely new issues). Only in the change log of the third issue (which I didn’t modify on the feature branch) it says “The issue has been copied from branch ‘feature’ to branch ‘master’”. My expectation was to get my modifications on the issue attributes copied from the feature to the master branch, but this didn’t happen.

Has anyone an idea what did I wrong?

Hello @Hansgeorg ,

Thanks for your explanations,

We took the time to try and reproduce the behavior you described on latest SQ LTS and latest SQ 10.5, and could not reproduce your issue (all issues were correctly transferred from the feature branch to the main branch)

Here’s the detail of the steps we took:

  • Have the SQ running, generate an analysis token
  • On SQ, create the project (Create Project > Manually), put master as main branch name
  • In CLI, create a new directory with some code inside
    mkdir test-project && cd test-project
    git init
    echo 'console.log("Hello world");' > index.js
    git add index.js && git commit -am "Initial commit"
    
  • In CLI, run an analysis
    sonar-scanner -Dsonar.projectKey=test-project -Dsonar.sources=. -Dsonar.host.url=[YOUR_SQ] -Dsonar.login=[YOUR_TOKEN]
    
  • In CLI, create a new branch dev using git checkout -b dev
  • In IDE, Modify the code to add code smells
    var a = 1;
    // TODO: Fix this:
    while (true) {
      a += 1;
    }
    console.log("Hello world");
    
  • In CLI, commit these changes using git commit -am "Dev"
  • In CLI, run an analysis on dev branch (same command than above with -Dsonar.branch.name=dev
  • On SQ, modify the “New Code” definition for the dev branch so that it uses master branch as reference, then re-run an analysis on dev branch
  • On SQ, Modify the issues as you described (comment, assigned to, resolution, severity)
  • In CLI, Re-run an analysis, this time on master branch (simulating a merge)
    sonar-scanner -Dsonar.projectKey=test-project -Dsonar.sources=. -Dsonar.host.url=[YOUR_SQ] -Dsonar.login=[YOUR_TOKEN] -Dsonar.branch.name=master
    

After this, all modified and unmodified issues were correctly tracked from the dev branch to the master branch. So, unfortunately, we can not really help more for now until we are able to reproduce the issue.

If you can consistently reproduce this issue, can you please share with us the exact steps to reproduce it? Including:

  • The exact code you are using
  • The exact commands you used to run the analysis, checkout branches etc

Thanks
Benjamin

1 Like