Hello, I am having an error when running a pipeline in azure devops, the pipeline generates an error in the sonarqube prepare phase, I am using sonar version 5.18.3 (Latest), in the self-hosted agent I have node16.13.2 and I tried with version 18 getting the same error the, error is the following.
##[error]Unhandled: Unexpected token ...
##[error]C:\Users\davidantolinez\Documents\my_agent\_work\_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.36.0\node_modules\hpagent\index.js:9
const { proxy, proxyRequestOptions, ...opts } = options.
the pipeline is this
jobs:
- job: 'analysis'
displayName: 'analysis with sonar'
steps:
- checkout: none
- task: SonarQubePrepare@4
inputs:
SonarQube: 'mySonarqube'
scannerMode: 'CLI'
configMode: 'manual'
cliProjectKey: 'nodejs'
cliProjectName: 'nodejs'
cliAdditionalArgs: >
sonar.sources=$(Build.SourcesDirectory)/src
# sonar.tests=$(Build.SourcesDirectory)/src/__test__
# sonar.exclusions=$(Build.SourcesDirectory)/src/__test__/**
# sonar.testExecutionReportPaths=$(Build.SourcesDirectory)/test-report.xml
# sonar.javascript.lcov.reportPaths=$(Build.SourcesDirectory)/coverage/lcov.info"
- task: SonarQubeAnalyze@4
displayName: 'Run SonarQube analysis'
- task: SonarQubePublish@4
inputs:
pollingTimeoutSec: '300'
Im using a docker image of sonar the lts version i also ran a jenkins pipeline to verify the connection with sonar and it worked, someone can help me with this error.
##[error]Unhandled: Unexpected token ...
##[error]C:\Users\davidantolinez\Documents\my_agent\_work\_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.36.0\node_modules\hpagent\index.js:9
const { proxy, proxyRequestOptions, ...opts } = options.
Can you offer a wider range of logs?
Is there a solution for this?
I have a similar problem where the agent is running on centos 7 with kernerl 3.
I can see that it looks like something does not like the “merge” javascript operator,
I wrote a quick JavaScript test function and ran on the centos.
github.com
The merge operation works fine on the centos.
And the version of node is 16.20.2
npm is 8.19.4
##[debug]loading ENDPOINT_AUTH_SCHEME_c876f7df-5dc1-4d93-bdb5-596fc3e75b75
##[debug]loading ENDPOINT_AUTH_PARAMETER_c876f7df-5dc1-4d93-bdb5-596fc3e75b75_USERNAME
##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
##[debug]loaded 15
##[debug]Agent.ProxyUrl=undefined
##[debug]Agent.CAInfo=undefined
##[debug]Agent.ClientCert=undefined
##[debug]Agent.SkipCertValidation=undefined
##[debug]task result: Failed
##[error]Unhandled: Unexpected token ...
##[debug]Processed: ##vso[task.issue type=error;]Unhandled: Unexpected token ...
##[debug]Processed: ##vso[task.complete result=Failed;]Unhandled: Unexpected token ...
##[error]/home/sean/myagent/_work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.36.0/node_modules/hpagent/index.js:9
const { proxy, proxyRequestOptions, ...opts } = options
SyntaxError: Unexpected token ...
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/sean/myagent/_work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.36.0/common/sonarqube/Endpoint.js:24:17)
##[debug]Processed: ##vso[task.issue type=error;]/home/sean/myagent/_work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.36.0/node_modules/hpagent/index.js:9
const { proxy, proxyRequestOptions, ...opts } = options
SyntaxError: Unexpected token ...
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/sean/myagent/_work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/4.36.0/common/sonarqube/Endpoint.js:24:17)
Finishing: SonarQubePrepare
Latest update Dec 4 - 4:32PM PST
I changed the version of the SonarQubePrepare@4 to SonarQubePrepare@5 and that seems to get past the JavaScript error.
Now facing the issue of trying to access the onsite agent from outside.
Starting: SonarQubePrepare
==============================================================================
Task : Prepare Analysis Configuration
Description : Prepare SonarQube analysis configuration
Version : 5.18.4
Author : sonarsource
Help : Version: 5.18.4. [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
##[error][SQ] API GET '/api/server/version' failed, error is request to http://localhost:9000/api/server/version failed, reason: connect ECONNREFUSED 127.0.0.1:9000
Finishing: SonarQubePrepare
##[error]Unhandled: Unexpected token …
This one is related to V4 of the tasks. Even if your agent has node 16/18 binaries, V4 of the task will always be run using node 6 which can’t parse the object destructuring, thus explaining this error. This can be fixed by moving to V5 of the tasks.
##[error][SQ] API GET ‘/api/server/version’ failed, error is request to http://localhost:9000/api/server/version failed, reason: connect ECONNREFUSED 127.0.0.1:9000
@sk92129 The error means that the agent running the task is trying to reach your SQ at localhost:9000
. This URL should be the URL of your SQ, from the perspective of where the task is running (either self-hosted agent, or Microsoft agent). You can fix this URL by updating your SonarQube Service Connection.
FYI: If the agent has to go through a proxy to reach the SQ, you will also have to set up HTTP_PROXY/HTTPS_PROXY environment variables.
Hope this helps!