I am working with SonarQube 10.5.1 Developer Edition for one of our projects. Our project currently has two branches named “main” [ MAIN BRANCH ] and trunk in SonarQube. However, our source code’s main branch has changed from main to trunk. Now, we want to analyze the quality gate based on the “trunk” branch, and we need to update SonarQube accordingly.
Here is the problem we’re facing:
Current Situation: The “main” [ MAIN BRANCH ] branch in SonarQube corresponds to what used to be “main,” but now We want to make “trunk” as the base and MAIN branch for the quality gate and comparison.
Attempted Solutions:
UI: We couldn’t find an option in the SonarQube UI (under project settings > branches) to rename or set the “trunk” as the new [ MAIN BRANCH ].
API Call: We tried executing a POST API call to rename the “main” [ MAIN BRANCH ] branch to “trunk”[ MAIN BRANCH ] as follows:
curl -X POST “https://sonarqube/api/project_branches/rename” --header “Authorization: squ_beaa9” -d “project=web” -d “name=trunk”
curl -X POST “https://sonarqube/api/project_branches/set_main” --header “Authorization: squ_beaa9” -d “project=web” -d “name=trunk”
We used multiple types of tokens (user, global, and project-specific), but the API did not return any response or error.
Objective: We want to ensure that when we create a PR, SonarQube compares it against the “trunk” branch (which should be the new [ MAIN BRANCH ]) for the quality gate, rather than the old “main” branch.
Could someone guide me on:
How to properly rename or reassign the “[ MAIN BRANCH ]” branch in SonarQube from main to trunk via the UI or API in SonarQube 10.5.1?
Any suggestions on how we can set the trunk branch as the base branch for quality gate comparisons?