Getting errors for New_code Metrics while using web API's

Hi Team,

We are using SonarQube 8.9 Enterprise Edition.

We are using two sonar Web API calls to get new_code metrics for projects.

1.api/measures/component?componentprojectkey&metricKeys=new_bugs,new_violations,new_code_smells

[Gives correct responses for both Overall code & New code Metrics]

  1. api/measures/search_history?component=projectkey&metrics=new_bugs,new_violations,new_code_smells

[Gives correct responses for overall code only not for new code]
Issue:
New code metrics for projects while using 2nd API it is not giving the values as shown below.

Reference:

GET api/measures/search_history

{
“paging”: {
“pageIndex”: 1,
“pageSize”: 100,
“total”: 2
},
“measures”: [
{
“metric”: “new_violations”,
“history”: [
{
“date”: “2017-01-23T17:00:53+0100”,
},
{
“date”: “2017-01-24T17:00:53+0100”,
}
}
“metric”: “ncloc”,
“history”: [
{
“date”: “2017-01-23T17:00:53+0100”,
“value”: “47”
},
{
“date”: “2017-01-24T17:00:53+0100”,
“value”: “47”
}
}

Can I know is there any solution for this?

Quick response is appreciated …

Thanks,
Naresh

Hi All,

Any updates?

Thanks,
Naresh

Hi Team,

Any updates on the issue?

Regards,
Naresh

Hey there.

The history of new_ metrics are not stored in SonarQube, as once they’re historical they’re no longer “new”.

Hi Colin,

Thanks for updates.

Got it…but I have one query

The API call shows the response as NULL for new code metrics but latest build results are showing the metric values in New code dashboard. I need to understand on this colin.

Thanks,
Naresh

Can you share a screenshot of what you’re seeing?

In SonarQube for the project the new_codesmells are 42 but in the response it is not showing the value.But for the bugs(overall code) it is showing the value with history.

I need to understand, why the API is not publishing the values of New_code metrics.

In sonarQube official documents, in the reference examples under the API call showing the values for New_code metrics.

Thanks,
Naresh

Hey there.

The project dashboard isn’t using GET api/measures/search_history – but you’re right, the docs for that Web API shouldn’t show new_ metrics. I’ve let the right team know we should update the response example.