Problem with specific baseline for new code

  • version: SonarQube 10.6
  • how is SonarQube deployed: Docker
  • what are you trying to achieve - set up specific analysis as baseline for new code

Hi.

I am trying to set up specific analysis as baseline for new code.
Accordingly to Defining new code
it is possible thorugh WebAPI.

But when I am trying do that I get
{“errors”:[{“msg”:“Invalid type: specific”}]}

Command that I am using is

curl -X POST -u “$SONARTOKEN:” “https:///api/new_code_periods/set” -d “project=<project>” -d “type=specific” -d “analysis=<analysis>”

What could be problem that causes command to fail?

Edit:
Solution.

  1. See comment from @Bachri_Abdel that marked as solution.
  2. Also instead of -d “analysis=<analysis key>" it should be -d “value=<analysis key>"

Hi @Peteris ,

It seems that the error you are encountering is due to the use of an incorrect type in your request. According to the API documentation for new code periods, the type parameter must be one of the following allowed types:

  • SPECIFIC_ANALYSIS - can be set at the branch level only
  • PREVIOUS_VERSION - can be set at any level (global, project, branch)
  • NUMBER_OF_DAYS - can be set at any level (global, project, branch)
  • REFERENCE_BRANCH - can only be set for projects and branches

In your command, you are using type=specific, which is not valid. If you want to set a specific new code period, you should use type=SPECIFIC_ANALYSIS (with the correct casing) and ensure that you are making the request at the branch level since this type cannot be set at the global or project level.

Here’s how you could correct your command:

curl -X POST -u "$SONARTOKEN:" "https:///api/new_code_periods/set" -d "project=<project>" -d "type=SPECIFIC_ANALYSIS" -d "analysis=<analysis>"

Make sure to replace <project> and <analysis> with the appropriate values as well.

1 Like

Thank you good sir :slight_smile:
indeed i had wrong value and after I used comand template that you specified I had progress.
Hoever I run into new error which also somewhat puzzles me. Maybe you have insight about it also?

{“errors”:[{“msg”:“New code definition type \u0027SPECIFIC_ANALYSIS\u0027 requires a value”}]

I provided analysis key in command… Not sure what more values it wants…

curl -X POST -u “<token>:” “https://<servername>/api/new_code_periods/set” -d “project=<myproject>” -d “type=SPECIFIC_ANALYSIS” -d “analysis=<analysis key>”

Hi @Peteris ,
It looks like you’re on the right track with correcting the type parameter to SPECIFIC_ANALYSIS , but the error message you’re encountering now indicates that the API expects more specific details regarding the analysis key you’re providing.

Make sure to replace <valid_analysis_key> with the actual key from a successful analysis. If you continue to have trouble, you may want to retrieve the list of analyses for the given project via the /api/project_analyses/search endpoint to confirm you’re using the right key.

1 Like

I did exactly that - I got list of existing analyses from that endpoint
…/api/project_analyses/search?project=myproject

For example got such analysis amongst whole list:

3
key 1f6d824b-c1d6-4697-94ac-a9eb78736654
date 2025-01-01T23:30:23+0000
events

But when I am using this 1f6d824b-c1d6-4697-94ac-a9eb78736654 for analysis parameter I still get
{“errors”:[{“msg”:“New code definition type \u0027SPECIFIC_ANALYSIS\u0027 requires a value”}]

Have no idea at moment what exactly sonar wants…

Anyone has ideas about this second error? :slight_smile:

{“errors”:[{“msg”:“New code definition type \u0027SPECIFIC_ANALYSIS\u0027 requires a value”}]

Never mind! :slight_smile:
Found solution for second issue:
instead of -d “analysis=<analysis key> it should be -d “value=<analysis key>

Also @Bachri_Abdel Thank you very much for type=SPECIFIC_ANALYSIS
It solved first issue :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.