After upgrade from 7.7 to 8.8: is there a parameter to define new code?

After upgrade from 7.7 to 8.8: and

I have upgraded SonarQube Developer Edition from 7.7 to 8.8 (7.7 → 7.9 LTS → 8.8).

This is my Maven command to start a SonarQube analysis:

mvn --no-transfer-progress \
    --global-settings /home/ubuntu/jenkins/workspace/foobar@tmp/config12345tmp \
    -Dmaven.repo.local=/home/ubuntu/jenkins/workspace/foobar/.repository \
    org.sonarsource.scanner.maven:sonar-maven-plugin: \ \

I have now defined New Code manually by going into the configuration of each individual project:

  • master: Previous Version
  • develop: Reference branch master
  • 7.2.0_preparations: Specific Analysis
  • All 7.2/* branches: Reference branch 7.2.0_preparations
  • All other branches: Reference branch develop

This was a very tedious work. It will have to be done again for every new project. It will have to be done again for every new 7.2/* branch.

Does there exist some analysis parameter that I can use, to define what the New Code is?
Something like this (pseudocode)

mvn sonar:sonar \ \

mvn sonar:sonar \ \
    -Dsonar.newcode=referenceBranch \

mvn sonar:sonar \ \
    -Dsonar.newcode=specificAnalysis \

mvn sonar:sonar \ \
    -Dsonar.newcode=referenceBranch \

mvn sonar:sonar \ \
    -Dsonar.newcode=referenceBranch \

I could then set all those parameters in a branch dependent Jenkins pipeline.

You can use the API api/new_code_periods/set to set the new code period. We use scripting to automatically set project master to specific analysis (as specified by developer) and to default branches to reference_branch=master.

1 Like

Hi Richard, I don’t understand your answer. Could you please elaborate?

  • What is the API api/new_code_periods/set?
  • What scripting language do you use?
  • Where do you execute your scripting?
  • When do you execute your scripting?
  • api/new_code_periods/set allows you to set/configure the new code period via code.
  • We use both Powershell (manual) and Groovy (Jenkins) to implement this api
  • We have separate Jenkins jobs that people can use to set their new code period
  • People can run this on-demand. Timing of setting the new code period generally requires thought and is best accomplished by a developer or tech lead at the appropriate time in the applicaiion life cycle.

Is this the API you are referring to?
I was not aware of its existence.

Oh ok it’s new since 8.0.

Are there any useful code examples on the web, that I can learn from?

Not that I’m aware of since it’s pretty new. If you’ve ever used the Sonarqube API it’s pretty straightforward.

I have never used the SonarQube API. I was not aware an API existed.


1 Like