We are in a situation where we recently upgraded from Community to Enterprise. Has been a great upgrade so far! Though there are some projects that are no longer in use that are interspersed with the active projects.
Since we want to keep this old project data for future reference, is there a way that I could re-label the old projects to something along the lines of archived-<project-name> directly using the SonarQube server GUI?
(Note: Since the old projects are no longer actively run, we are not able to update the project name by rerunning the analysis scans with a new project name set.)
changing the sonar.project.name is simply done by changing the sonar.projectName
in the next analysis for an existing Sonarqube project, which is no option in your case.
Right now there is no web api call for renaming projects, only for project key api/projects/update_key .
Did a rename in Sonarqube DB - normally you should treat the DB as black box - when i needed to rename a bunch of project names.
Here’s an example using Groovy (needs mssql jdbc driver and dll for integrated authentication)
with a MSSQL database
import groovy.sql.Sql
import groovy.sql.DataSet
// DB
def dbserver = $/XYZ1234\MSSQL64/$
def dbname='XXX_SonarQube_XX'
def list = []
def sql1 = Sql.newInstance("jdbc:sqlserver://$dbserver;databaseName=$dbname;integratedSecurity=true",
"", "", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
def sql2 = Sql.newInstance("jdbc:sqlserver://$dbserver;databaseName=$dbname;integratedSecurity=true",
"", "", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
sql1.eachRow("select * from dbo.projects where name LIKE '%.FOO -%'") { row ->
// println "$row.name"
s = "Update dbo.projects SET name=${row.name - '.FOO'} where name=$row.name"
// println s
sql2.execute(s)
}
Don’t know your criteria to identify the project names to be changed, but the other part is
something like
s = "Update dbo.projects SET name=${'archived - ' + row.name} where name=$row.name"
I am not sure that project renaming is the right solution for your problem.
As @anon67236913 mentioned:
The standard way to rename projects is by re-analyzing them and you probably don’t want to do that
The risky way (unsupported, use at your own risks), it to directly edit the database. I strongly discourage this
I can suggest something different: You could use project tags to mark projects that are archived (and potentially also add tags for projects that are active).
This can easily be done manually (requires project administration permission on the tagged project) or programmatically (using api/project_tags/set).
Tagging projects that are active can be useful because on the SonarQube main projects page, you can only filter by projects that do have a given tag (eg active) not by projects that do not have have a tag (filtering (showing) projects that are not archived is not possible).