opendevstack / ods-jenkins-shared-library

Shared Jenkins library which all ODS projects & components use - provisioning, SonarQube code scanning, Nexus publishing, OpenShift template based deployments and repository orchestration
Apache License 2.0
69 stars 57 forks source link

odsComponentStageScanWithSonar fails when requireQualityGatePass is enabled #1109

Closed gerardcl closed 1 month ago

gerardcl commented 1 month ago

Describe the bug When enabling requireQualityGatePass in odsComponentStageScanWithSonar, with the latest Jenkins agents update the cURL command is no longer defining the query as a HTTP GET but a POST making the call fail with HTTP 405 and later resulting as an UNKNOWN quality gate and hence failing the whole pipeline build. We have been debugging and the same cURL command before the Jenkins agents updates was triggering a GET but now cURL defaults to POST.

To Reproduce Steps to reproduce the behavior:

  1. Enable requireQualityGatePass in your odsComponentStageScanWithSonar Jenkinsfile stage
  2. Commit and push
  3. See error in the log output section

Expected behavior The cURL command must send a GET and not a POST.

Screenshots N/A

Affected version (please complete the following information):

Log Output (ensure to remove any confidential information like tokens, project names, etc.

[Pipeline] sh (Get status of quality gate)
+ curl -s -u ******: --url https://sonarqube.myinstance.com/api/qualitygates/project_status --data-urlencode projectKey=one-project --data-urlencode branch=feature/branch
[Pipeline] }
[Pipeline] // withSonarQubeEnv
[Pipeline] readJSON
[Pipeline] echo
SonarQube Quality Gate value: UNKNOWN
[Pipeline] error
[Pipeline] }
[Pipeline] // stage
[Pipeline] echo
[SonarQube Analysis-componentId] **** ENDED stage 'SonarQube Analysis' for component 'componentId' branch 'feature/branch' **** (took 58795 ms)
[Pipeline] }
[Pipeline] // wrap
[Pipeline] stage
[Pipeline] { (odsPipeline error)
[Pipeline] echo
WARN: [componentId] ***** Finished ODS Pipeline for componentId (with error) ***** (took 1091868 ms)
[Pipeline] echo
WARN: Error: hudson.AbortException: Quality gate unknown!

Additional context Force --get flag.

metmajer commented 1 month ago

Thanks @gerardcl !

gerardcl commented 1 month ago

Update: we found out the issue was not due to cURL updates rather SonarQube API changes. Basically cURL is always sending URL encoded data as body except when using --get explicit flag...