How to update Azure Pipeline for Sonar scanner to use Java 17

Note: earlier all Steps were working fine starts failing after java 11 supports ended

This is what we were using

 # - task: SonarCloudAnalyze@1.38.0
    # condition: and(succeeded(), eq(variables.IsSonarEnabled, 'true'))

and now updated to this

   - task: SonarCloudAnalyze@1.38.0 or SonarCloudAnalyze@1
     inputs:
       jdkversion: 'JAVA_HOME_17_X64'

I can see all 3 available java vesion in Devops Pipeline
tempsnip

but it fails w/ below errors

ERROR: Error during SonarScanner execution

##[error]java.lang.IllegalStateException: Failed to parse JSON in SONARQUBE_SCANNER_PARAMS environment variable

@mickaelcaro @Colin Could one of you please help

Hello Could anyone from @sonarcloud take a look this issue

Hi,

Per the FAQ, please don’t @ users not already involved in your thread.

From your first post, it seems that you changed your build config and began getting an error. What did you make of that error? What have you tried?

 
Ann

Actually, I was forced to make that change after SonarScanner only supported Java 17 and higher I guess

Based on available online posts, I’ve added
Note: Attached yml

   - task: SonarCloudAnalyze@1
     inputs:
       jdkversion: 'JAVA_HOME_17_X64'

earlier it was

   - task: SonarCloudAnalyze@1.38.0

but then getting below error

##[error]java.lang.IllegalStateException: Failed to parse JSON in SONARQUBE_SCANNER_PARAMS environment variable
pipeline.txt (14.0 KB)

@ganncamp ^^

Hi,

I really urge you to read the FAQ. On this occasion, the section I have in mind is this one:

I created a topic, when can I expect a response?

This is an open community with people volunteering their free time to provide assistance. We’re eager to contribute to the community, but you are not guaranteed a fast response.

Be patient

  • Wait a few days before bumping a topic that hasn’t received a response.
  • Do not @name mention individuals not involved in the topic.

Regarding your situation, what happens when you revert your change?

 
Ann

it failed the build since its not automatically pulling Java 17 version

Hi,

My first thought was a syntax error, which is why I asked you to verify that reverting gets a different error.

But now I’m wondering if something else is going on. Can you echo the SONARQUBE_SCANNER_PARAMS environment variable so we can see what’s in it?

 
Thx,
Ann

could you please provide me with the steps to produce what you asked for

Thanks
Sumit

Hi Sumit,

I’m not an Azure expert. Searching took me to SO.

 
HTH,
Ann

Hi @ganncamp

I’ve added this step after SOnarCloudPrepare step but its getting printed as its , do I need to do anything else to print its value like enable debug or variable syntax is wrong

  - task: CmdLine@2
    inputs:
      script: |
        echo $env:SONARQUBE_SCANNER_PARAMS

Thanks
Sumit

Hi Sumit,

As I said, this is not my area of expertise, but that doesn’t match what I’m seeing in the SO answer I linked too…

 
Ann

Hi @ganncamp

maybe you can ask someone in your team if possible ? the reference you gave and what i did is two different way nothing more

Thanks
Sumit

Hi @ganncamp you can refer to this thread, we are from the same team and he’s referring to the same issue, you’ll find the SONARQUBE_SCANNER_PARAMS in below thread

Hi @ganncamp When I dig deep into this figured out there’s Warning

Failed to parse properties from the environment variable 'SONARQUBE_SCANNER_PARAMS' because 'Error reading JObject from JsonReader. Current JsonReader item is not an object: String. Path '', line 1, position 3935.

I just change some Project/Org variables to random

{\"sonar.host.url\":\"https://sonarcloud.io/\",\"sonar.token\":***,\"sonar.organization\":\"ProjectName\",\"sonar.projectKey\":\"ProjectNameWeb\",\"sonar.projectName\":\"ProjectNameWeb\",\"sonar.projectVersion\":\"1.0\",\"sonar.pullrequest.key\":\"8130\",\"sonar.pullrequest.base\":\"master\",\"sonar.pullrequest.branch\":\"pbi/364601/Sonar-Cloud-Scanner-update-to-Java-17\",\"sonar.pullrequest.provider\":\"vsts\",\"sonar.pullrequest.vsts.instanceUrl\":\"https://dev.azure.com/defDevOps/\",\"sonar.pullrequest.vsts.project\":\"Digital\",\"sonar.pullrequest.vsts.repository\":\"Web\",\"sonar.scanner.metadataFilePath\":\"D:\\\\a\\\\_temp\\\\sonar\\\\50954\\\\9de1c6b0-720e-ec07-32ec-64a0533664d5\\\\report-task.txt\",\"sonar.exclusions\":\"'**/*.bin, **/bin/**, **/App_Browsers/**, **/App_Config/**, **/App_Data/**, **/App_Start/**, **/xsl/**, **/Packages/**, **/TravelForum/**, **/*.config, **/*.dll, **/*.css, **/jquery.js, **/idangerous.swiper-2.1.js, **/src/Project/ProjectName/code/Content/**, **/src/Project/ProjectName/code/scripts/**, **/src/Project/ProjectName/code/sitecore/**, **/src/Feature/FulfillmentForms/code/Scripts/modules/fulfillmentForms/**, **/src/Feature/MarketingPages/code/scripts/app/**, **/src/Feature/MyAccount/MyReservations/code/scripts/app/**, **/src/Feature/Tools/code/scripts/**, **/src/Feature/WebAdmin/code/scripts/app/**, **/src/Foundation/JavascriptCommon/code/scripts/app/Angular/**, **/src/Project/ProjectName/code/sitecore modules/Web/ExperienceExplorer/**, **/src/Foundation/Enterprise/Services/code/Service References/**, **/src/Foundation/SitecoreExtensions/code/sitecore/shell/Applications/Dialogs/**, **/src/Feature/FulfillmentForms/code/Scripts/modules/fulfillmentForms/**, **/src/Feature/MarketingPages/code/scripts/mvcfoolproof.unobtrusive.min.js, **/src/Feature/MarketingPages/code/scripts/MvcFoolproofJQueryValidation.min.js, **/src/Feature/MarketingPages/code/scripts/MvcFoolproofValidation.min.js, **/src/Feature/MyAccount/MyReservations/code/scripts/mvcfoolproof.unobtrusive.min.js, **/src/Feature/MyAccount/MyReservations/code/scripts/MvcFoolproofJQueryValidation.min.js, **/src/Feature/MyAccount/MyReservations/code/scripts/MvcFoolproofValidation.min.js, **/src/Feature/Tools/code/Scripts/**, **/src/Feature/WebAdmin/code/Scripts/angular/**, **/src/Feature/WebAdmin/code/Scripts/bootstrap/**, **/src/Feature/WebAdmin/code/Scripts/compatibility/**, **/src/Feature/WebAdmin/code/Scripts/DataTables-1.9.4/**, **/src/Feature/WebAdmin/code/Scripts/jquery/**, **/src/Feature/WebAdmin/code/Scripts/locales/**, **/src/Feature/WebAdmin/code/Scripts/RangeSlider/**, **/src/Feature/WebAdmin/code/Scripts/bootstrap-datepicker.js, **/src/Foundation/JavascriptCommon/code/scripts/lib/**, **/src/Project/ProjectName/code/Content/js/**, **/src/Project/ProjectName/code/scripts/deferred/**, **/src/Project/ProjectName/code/scripts/modules/underscore/**, **/src/Project/ProjectName/code/scripts/modules/vendor.js, **/src/Project/ProjectName/code/scripts/modules/vendordefered.js, **/src/Project/ProjectName/code/scripts/ai.0.22.19-build00125.js, **/src/Project/ProjectName/code/scripts/ai.0.22.19-build00125.min.js, **/src/Project/ProjectName/code/scripts/bootstrap.js, **/src/Project/ProjectName/code/scripts/bootstrap.min.js, **/src/Project/ProjectName/code/scripts/jquery-1.10.2.js, **/src/Project/ProjectName/code/scripts/jquery-1.10.2.min.js, **/src/Project/ProjectName/code/scripts/jquery.validate-vsdoc.js, **/src/Project/ProjectName/code/scripts/r.js, **/src/Project/ProjectName/code/sitecore modules/Web/ExperienceExplorer/**, **/src/Project/ProjectName/code/scripts/nonDeferred/**' sonar.inclusions='**/src/Project/ProjectName/code/Content/styles/def.css, **/src/Project/ProjectName/code/Content/styles/abc.css, **/src/Project/ProjectName/code/Content/styles/def_authoring.css, **/src/Project/ProjectName/code/Content/styles/abc_authering.css, **/src/Feature/WebAdmin/code/Scripts/ProjectName.typeahead/typeahead.js, **/src/Feature/WebAdmin/code/Scripts/ProjectName.webadmin/ProjectName.changePasswordAudit.js, **/src/Project/ProjectName/code/scripts/nonDeferred/ProjectName-sitecatalyst.js'\"}

Validated that this is not a valid JSON and getting below error

Parse error on line 1:
{"sonar.host.url":
-^
Expecting ‘STRING’, ‘}’, got ‘undefined’

Let me know if I need to provide something else to resolve this issue

Thanks
Sumit

Hi Sumit,

Let’s back up. Are your build agents self-hosted?

 
Ann

@ganncamp Yes

Hi,

Then simply update them to replace Java 11 with Java 17 and put your pipeline back to its pre-error state.

 
HTH,
Ann

Hi

got the below error when I updated my SonarCloudPrepare and Analysis to use java 17

2024-01-31T08:15:36.7154685Z ##[error]ERROR: 

The version of Java (11.0.22) used to run this analysis is deprecated, and SonarCloud no longer supports it. Please upgrade to Java 17 or later.

Steps I modified

  - task: SonarCloudPrepare@1
    inputs:
      jdkversion: 'JAVA_HOME_17_X64'
  - task: SonarCloudAnalyze@1.38.0
    displayName: 'Sonar Cloud Prepare Task'
    inputs:
      jdkversion: 'JAVA_HOME_17_X64' 

Let me know your thoughts/feedback

Thanks
Sumit