How to rename a project in SonarQube 5.1?
Asked Answered
M

10

26

I can't find how to rename a project in SonarQube 5.1.

Once created, how one can change project name, key, branch, from the web dashboard?

SonarQube's documentation doesn't help.

Mikes answered 28/5, 2015 at 16:9 Comment(0)
E
12

You need to "update the project key" (I always think that the Sonar terminology here isn't very helpful)

https://docs.sonarqube.org/display/SONAR/Project+Settings#ProjectSettings-UpdatingProjectKey

and then re-run the analysis (with the new project key, so having updated your sonar-project.properties or build.xml or pom.xml, etc)

Eous answered 28/5, 2015 at 17:4 Comment(4)
I'll give it a try. Documentation is not up-to-date. It's in Settings > Update key now and not Configuration > Update key.Mikes
BTW: it only updates the technical key, the name shown on the UI isn't affected. I changed that it in the DB, too.Tycho
What did you change in the DB to update UI display name?Lorrimor
In 7.x I found that updating the key and running the analysis causes the name to be updated automatically (for a Maven project)Holmun
G
23

In SonarQube 5.1 the project name can't be changed from the web dashboard (Probably it will not be possible in the future as well).

I configure my SonarQube projects sonar-project.properties where I only have to change this line:

sonar.projectName=MyNewProjectName

Rerun the analysis to see the result in the web dashboard.

Gens answered 7/3, 2016 at 16:22 Comment(4)
In SonarQube 6.5 you can update your project key by switching to your project and then "Administration" -> "Update key". But the project name is still unchangeable as far as I know.Karaite
Why is it not possible in the future?Ole
Which 'file' are you configuring here? Otherwise this answer is useless.Reseda
Updating just the sonar.projectKey did not work for me to update the name on the dashboard, but also updating sonar.projectName did [Version 6.7.7 (build 38951)]. Thank you!Hydantoin
E
12

You need to "update the project key" (I always think that the Sonar terminology here isn't very helpful)

https://docs.sonarqube.org/display/SONAR/Project+Settings#ProjectSettings-UpdatingProjectKey

and then re-run the analysis (with the new project key, so having updated your sonar-project.properties or build.xml or pom.xml, etc)

Eous answered 28/5, 2015 at 17:4 Comment(4)
I'll give it a try. Documentation is not up-to-date. It's in Settings > Update key now and not Configuration > Update key.Mikes
BTW: it only updates the technical key, the name shown on the UI isn't affected. I changed that it in the DB, too.Tycho
What did you change in the DB to update UI display name?Lorrimor
In 7.x I found that updating the key and running the analysis causes the name to be updated automatically (for a Maven project)Holmun
A
6

To change the projet name in UI run this SQL query :

UPDATE sonar.projects
SET  name = 'NEW_PROJECT_NAME',
long_name = 'NEW_PROJECT_NAME'
WHERE kee = 'PROJECT_KEY'
Advowson answered 1/9, 2016 at 8:13 Comment(2)
In my SonarQube 7.8 database (SQL Server), the projects table was a member of the dbo schema, not the sonar schema. But other than that, the update statement is correct and it worked for me.Mcmaster
long_name is not used anymore in last versions of SonarQubeHarbard
S
6

If you are using jenkins and your sonar build is a post build step. You may add the property mentioned by @adrianko to your goals.

$SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_AUTH_TOKEN -Dsonar.projectName="YOUR PROJECT NAME"
Sterculiaceous answered 2/12, 2016 at 18:40 Comment(0)
R
4

In SonarQube 8.6 (PostgreSQL), execute SQL

UPDATE projects
SET name = 'NEW_PROJECT_NAME'
WHERE kee = 'PROJECT_KEY';

UPDATE components
SET "name" = 'NEW_PROJECT_NAME',
  long_name = 'NEW_PROJECT_NAME'
WHERE kee = 'PROJECT_KEY';
Rectocele answered 31/12, 2020 at 9:54 Comment(0)
D
1
CREATE PROCEDURE usp_ChangeProjectName
    @CaseSensitiveProjectKeyToChange VARCHAR(300),
    @NewProjectName VARCHAR(300)
AS
BEGIN
    SET NOCOUNT ON;

    IF (SELECT COUNT(*) FROM dbo.projects WHERE kee = @CaseSensitiveProjectKeyToChange and scope = 'PRJ') > 1
    BEGIN
    RAISERROR ('Operation would affect more than one record, cancelling for safety.', 16, 1)
END

UPDATE 
    dbo.projects
SET 
    name = @NewProjectName,
    long_name = @NewProjectName 
WHERE 
    kee = @CaseSensitiveProjectKeyToChange and
    scope = 'PRJ'   
END
GO

Sample Usage usp_ChangeProjectName2 '<project key>', '<new name>'

Diabolize answered 14/6, 2017 at 12:56 Comment(0)
C
1

Just add or edit gradle.properties file as below:

org.gradle.java.home=C\:\\Program Files\\Java\\jdk1.8.0_191

org.gradle.jvmargs=-Xmx1536m

systemProp.sonar.host.url=https://abc.xyz.com

#----- Token generated from an account with 'publish analysis' permission
systemProp.sonar.login=your token goes here

systemProp.sonar.projectName=ProjectName

Please change the path of JDK as per your system configuration, sonarqube server url, access token and finally the name of project that you want to give. By default in android studio project name is app

Just let me know if anybody face any problem while integration of sonarqube.

Concession answered 16/10, 2019 at 4:22 Comment(0)
D
1

I tried all the way but it did not work for me . At last my bamboo server gave me some hint . Instead of using projectName pror you can use "/n:" key.. i.e /n:"your project name".

Disembody answered 24/5, 2021 at 10:51 Comment(1)
This was what worked for me. I updated the project key in the GUI, then ran SonarScanner.MSBuild.exe with /k:"My New Key" /n:"My New Key" (assuming you want the key to be the project name)Heal
I
0

There is no possibility to rename the project in the web frontend (tested with Sonarqube V 9.3).

But you can change the project name by running the sonar scanner commandline interface locally and passing the new project name (also the sonar token and the project key) as parameter (If sonar-scanner is started in the same directory in which sonar-project.properties is located, the properties are also read from this file):

sonar-scanner -Dsonar.projectName="enter_new_projectname_here“ -Dsonar.login="your_sonar_token“ -Dsonar.projectKey="your_project_key“

On macOS the sonar scanner can be installed with homebrew:

brew install sonar-scanner

For other platform see https://github.com/SonarSource/sonar-scanner-cli

Indecency answered 23/2, 2022 at 9:41 Comment(0)
S
0

In our case, when we changed -Dsonar.projectName and ran the analysis on developers' branches, nothing changed. Until we ran analysis on the main (master) branch -> then project name was automatically changed

Salome answered 1/8, 2023 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.