simondel / sonar-buildbreaker-vsts Goto Github PK
View Code? Open in Web Editor NEWVSTS task to break your build when you failed the quality gate
License: Apache License 2.0
VSTS task to break your build when you failed the quality gate
License: Apache License 2.0
Hello Team,
We are using the SonarQube build breaker task 2 times in the same Azure DevOps build pipeline, since we have 2 separate scans configured. So we will scan the webui source code(java) which gets posted to one Sonar project, then later in the pipeline we scan the DB source code, which gets posted to another Sonar project. We would like to fail the build if either quality gate fails. However, with this configuration we get the following error when the second build breaker task executes:
##[error]The operation was canceled.
Is this type of configuration supported?
Thanks in advance for the insight!
-Tom
When using this step 'SonarCloud build breaker" in azure devops ideally it should fail if any one of the quality gates fail but it is failing only if "bugs" are reported and not failing for any other quality gates.
can you please explain the functionality of this step.
Version of Build Breaker: 8.0.0
Version of SonarQube: 4.7.2
Tasks always succeeding but getting the following:
Getting task report from file undefined
(node:7688) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: path must be a string or Buffer
or
Number of analyses in this build: 0
Summary of statusses:
##[section]Finishing: Break build on quality gate failure
Hi Simon.
I'm using sonar 6.7 and build breaker 8 and I'm getting the following output from build breaker:
##[section]Starting: Break build on quality gate failure
==============================================================================
Task : SonarQube build breaker
Description : Break the build when the quality gate fails.
Version : 8.0.0
Author : Simon de Lang
Help :
==============================================================================
Number of analyses in this build: 0
Summary of statusses:
##[section]Finishing: Break build on quality gate failure
I can see from a previous step that the report-tasks.txt is being written to the following path:
13:40:25.010 DEBUG: Report metadata written to D:\VSTS\Agents\A\_work\179\.sonarqube\out\.sonar\report-task.txt
Any ideas? Cheers!
Allways fails the build with the following message: Unhandled: Cannot read property 'analysisId' of undefined
First of all thank you for this SonarCloud build breaker extension. We are using it in our Azure DevOps pipelines and has been really helpful.
Currently this is the output that we get when the quality gate is failing
I was wondering if it could be possible to add there in the logs the reason(s) why the quality gate has failed.
It would be a great improvement for us.
Best regards!
Sonarqube version 6.7
this extension task version 8
The sonarqube web page showing the quality gate is failed. But this extension doesn't stop the build pipeline.
Log of this extension
Number of analyses in this build: 0
Summary of statusses:
The build breaker task started to fail (i.e. not breaking the build when it should, the task is always green) for all our pipelines between August 14 and August 23 according to our history, with this error:
Getting task report from file undefined
(node:20441) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: path must be a string or Buffer
This matches with
We're using SonarQube 6.7.3.
The analysis summary appears properly in the build summary.
The Publish Quality gate task does not report any issue and the analysis can be seen in Sonar.
Full debug output of the buid breaker task:
==============================================================================
Task : SonarQube build breaker
Description : Break the build when the quality gate fails.
Version : 7.0.5
Author : Simon de Lang
Help :
==============================================================================
##[debug]agent.TempDirectory=/var/vsts/work/_temp
##[debug]loading inputs and endpoints
##[debug]loading INPUT_SONARQUBE
##[debug]loading ENDPOINT_AUTH_11da1f38-54c8-4f4d-bfdb-d9b17701cc40
##[debug]loading ENDPOINT_AUTH_SCHEME_11da1f38-54c8-4f4d-bfdb-d9b17701cc40
##[debug]loading ENDPOINT_AUTH_PARAMETER_11da1f38-54c8-4f4d-bfdb-d9b17701cc40_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]loading SECRET_SONARQUBE_ENDPOINT
##[debug]loaded 9
##[debug]Agent.ProxyUrl=undefined
##[debug]Agent.CAInfo=undefined
##[debug]Agent.ClientCert=undefined
##[debug]Agent.SkipCertValidation=undefined
##[debug]SonarQube=11da1f38-54c8-4f4d-bfdb-d9b17701cc40
##[debug]11da1f38-54c8-4f4d-bfdb-d9b17701cc40=https://*********/
##[debug]11da1f38-54c8-4f4d-bfdb-d9b17701cc40 auth param apitoken = null
##[debug]11da1f38-54c8-4f4d-bfdb-d9b17701cc40 auth param username = ***
##[debug]11da1f38-54c8-4f4d-bfdb-d9b17701cc40 auth param password = null
##[debug]organization=null
##[debug]Build.BuildNumber=20190923.4
##[debug]Agent.TempDirectory=/var/vsts/work/_temp
##[debug]defaultRoot: '/var/vsts/work/_temp'
##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
##[debug]findOptions.followSymbolicLinks: 'true'
##[debug]matchOptions.debug: 'false'
##[debug]matchOptions.nobrace: 'true'
##[debug]matchOptions.noglobstar: 'false'
##[debug]matchOptions.dot: 'true'
##[debug]matchOptions.noext: 'false'
##[debug]matchOptions.nocase: 'false'
##[debug]matchOptions.nonull: 'false'
##[debug]matchOptions.matchBase: 'false'
##[debug]matchOptions.nocomment: 'false'
##[debug]matchOptions.nonegate: 'false'
##[debug]matchOptions.flipNegate: 'false'
##[debug]pattern: 'sonar/20190923.4/**/report-task.txt'
##[debug]findPath: '/var/vsts/work/_temp/sonar/20190923.4'
##[debug]statOnly: 'false'
##[debug]findPath: '/var/vsts/work/_temp/sonar/20190923.4'
##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
##[debug]findOptions.followSymbolicLinks: 'true'
##[debug]0 results
##[debug]found 0 paths
##[debug]applying include pattern
##[debug]adjustedPattern: '/var/vsts/work/_temp/sonar/20190923.4/**/report-task.txt'
##[debug]0 matches
##[debug]0 final results
Getting task report from file undefined
(node:20441) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: path must be a string or Buffer
##[section]Finishing: Break build on SonarQube quality gate failure
Whereas the Publish task ends with this:
##[debug]adjustedPattern: '/var/vsts/work/7/**/report-task.txt'
##[debug]1 matches
##[debug]1 final results
##[debug][SQ] Searching for **/report-task.txt - found 1 file(s)
##[debug][SQ] Read Task report file: /var/vsts/work/7/s/target/sonar/report-task.txt
##[debug][SQ] Parse Task report file: projectKey=**********************
Thanks for your help
We were using version 6, which suddenly stopped working without any obvious reason.
I enabled debug output, here's part of that:
##[debug]76382 results
##[debug]found 76382 paths
##[debug]applying include pattern
##[debug]adjustedPattern: 'C:\DeltaPi\agent_work\10*\report-task.txt'
##[debug]1 matches
##[debug]1 final results
##[debug]SONARQUBE_ENDPOINT=**
##[debug]task result: Failed
##[error]Unhandled: Cannot read property 'status' of undefined
##[debug]Processed: ##vso[task.issue type=error;]Unhandled: Cannot read property 'status' of undefined
##[debug]Processed: ##vso[task.complete result=Failed;]Unhandled: Cannot read property 'status' of undefined
The file does appear to exist (C:\DeltaPi\agent_work\10.sonarqube\out.sonar\report-task.txt) and has the following contents:
projectKey=DeltaPi
serverUrl=http://d1nlbodwrvsts:9000
serverVersion=6.7.5.38563
dashboardUrl=http://d1nlbodwrvsts:9000/dashboard/index/DeltaPi
ceTaskId=AWyUSQKpYJwQvCdTe4Ny
ceTaskUrl=http://d1nlbodwrvsts:9000/api/ce/task?id=AWyUSQKpYJwQvCdTe4Ny
Note that this file only contains LineFeed line endings (not sure if that matters)
We are using SonarQube LTS so nothing should've changed there...
I tried using the latest version of the plugin, version 7, the following is part of the debug output:
##[debug]pattern: 'sonar\20190815.3*\report-task.txt'
##[debug]findPath: 'C:\DeltaPi\agent_work_temp\sonar\20190815.3'
##[debug]statOnly: 'false'
##[debug]findPath: 'C:\DeltaPi\agent_work_temp\sonar\20190815.3'
##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
##[debug]findOptions.followSymbolicLinks: 'true'
##[debug]0 results
##[debug]found 0 paths
##[debug]applying include pattern
##[debug]adjustedPattern: 'C:\DeltaPi\agent_work_temp\sonar\20190815.3*\report-task.txt'
##[debug]0 matches
##[debug]0 final results
Getting task report from file undefined
(node:5036) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: path must be a string or Buffer
It can't find the file, which makes sense as it's not located in the temp folder.
What can be done to fix it?
I have not originally configured the pipeline, the one who did has left the company, so please excuse me for any of my ignorance.
@remkoseelig mentioned in #1 that the has the following issue:
Using VSTS and SonarQube 6.7.1 I the build/plugin fails with: "Cannot read property 'task' of undefined".
@nboeckmann has this same issue but with TFS:
Hey,
I'm having the same issue as @remkoseelig and I'm using the 7.x version. I'm still getting the same error message as he does: "Cannot read property 'task' of undefined".
I'm using SQ Server 6.7.1 and I can see in the access.log that the queries are made OK and that content is returned. I've also validated the output of the queries and they seem to be ok considering what you have written earlier in this post.
Do you have any idea what can be the reason for it?
Hi all,
I'm trying to run a pipeline on Azure DevOps & found a new error on SonarCloud Build Breaker: it's failling appearently due to a SQL error. The log is attached.
SonarCloud Build Breaker Error Log.txt
In extensions/sonarqube/tasks/buildbreaker/common/checkQualityGateTask.ts, "has" is duplicated (line 26), and "statuses" is misspelled as "statusses" (line 23).
This file has an exact copy in the "sonarcloud" extension, which has the same errors.
we use dotnet-sonar and sonarqube-scanner in the tfs build pipeline.
just wondering whether this tool can be used along with those tools?
Hello,
We are using sonarcloud to analyze .net core projects with Azure DevOps.
Tasks in the pipeline:
task: CmdLine@2
displayName: Dotnet sonarscanner start
inputs:
script: |
echo Dotnet sonarscanner start
dotnet “SonarScanner.MSBuild.dll” begin /k:"" /o:"" /d:sonar.host.url=“https://sonarcloud.io” /d:sonar.login=""
Task to execute .net core build
task: CmdLine@2
displayName: Dotnet sonarscanner end
inputs:
script: |
echo Dotnet sonarscanner end
dotnet “$(Build.SourcesDirectory)\Tools\Sonarqube\SonarScanner.MSBuild.dll” end
- task: sonarcloud-buildbreaker@2
inputs:
SonarCloud: 'sonarcloud'
organization: 'genomics'
We are getting the below logs from the build breaker task:
Starting: sonarcloudbuildbreaker
==============================================================================
Task : SonarCloud build breaker
Description : Break the build when the quality gate fails.
Version : 2.1.0
Author : Simon de Lang
Help :
==============================================================================
Number of analyses in this build: 0
Summary of statusses:
Finishing: sonarcloudbuildbreaker`
Not sure why the output contains "Number of analyses in this build: 0".
Also the build should be failed, but it succeeds. Not sure what's wrong in the pipeline setup.
Any inputs will be helpful. Thanks in advance.
FYI I ported your code to GH Actions, got the sonarcloud version working here: https://github.com/dylan-smith/sonarcloud-buildbreaker
Gonna do a sonarqube server version next.
After the recent 2.1.1 upgrade, all our pipelines started breaking, with the error:
##[error]Unhandled: Unexpected token ...
Finishing: Break build on quality gate failure
Is there a work around?
Hi Simondel,
Appreciate your support in the below issue regarding SonarQube in our Azure pipeline.
I have used some Azure built-in tasks to integrate our SonarQube instance and enable the code analysis inside our pipeline. I have used “SonarQubePrepare@4” and “SonarQubeAnalyze@4” tasks , those went fine and passed but when I try to use the tasks as “SonarQubePublish@4” to enable publishing of the SonarQuality gate and then use “sonar-buildbreaker@8” to stop the pipeline in case of failure, publishing stage is usually not passing with the below error.
##[error][SQ] Could not fetch task for ID 'AXcXIGd0GolG0E5ghxBy'
##[error][SQ] API GET '/api/ce/task' failed, status code was: 404
##[error][SQ] API GET '/api/ce/task' failed, status code was: 404
##[error][SQ] API GET '/api/ce/task' failed, status code was: 404
##[error][SQ] API GET '/api/ce/task' failed, status code was: 400
I have searched a lot and all clues are pointing that “report-task.txt” file may be cached from old builds and the solution is that I remove it but actually I am not sure where it is generated inside the working directory of the pipeline. Worth to be mentioned that although this solution is proposed, many people are still complaining from the same issue even after following it and the case is not resolved yet on many platforms.
Thanks to support how can I resolve this issue. Any proposal will be much appreciated as it’s a great blocker to us since stopping the pipeline based on the SonarQube quality gate result is very important stage in our pipelines.
I would like to execute a task after the build breaker if the quality gate failed. Something like this would help:
- task: sonar-buildbreaker@8
name: buildbreaker
displayName: Check Quality Gate
continueOnError: true
inputs:
SonarQube: SonarQube
OutputVariableName: myVariableName
- task: xxxxx
condition: $(buildbreaker.myVariableName)
...
I can submit a PR if you want.
the endpoint is available as serverUrl in report-task.txt file.
So why we need to pass the endpoint explicitly in the task?
Checking since we dont need to pass the endpoint in task "Publish Quality Gate Result"!
I got a question, I have extension “Break build on quality gate failure” version 6.2.3, and it seems that it required has "Publish Quality Gate Result", if i disable that task i get the following error:
But i got a problem with task Publish Quality Gate result, it taking so long to finish, despite that the task "Run Code Analysis" is finished. Why this happen? it is necessary to have the task "Publish Quality Gate Result" configured in my pipeline before “Break build on quality gate failure” task?
I have SonarQube 4.3.0.
Thanks for your help.
A new version of the SQ extension has change the path of the report-task.txt
Now, it use the buildId instead of the buildName in the path.
The new file path is exposed from the SQ extension as a json variable send to the pipeline (log command)
Since the update of the sonar plugin to version 4.7.0 we get the following error:
(node:4115) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: path must be a string or Buffer
Getting task report from file undefined
We checked the changes of the sonar plugin and recognised that the result will now placed in the tmp directory rather than the build folder.
see:
common/ts/sonarqube/TaskReport.ts
in the following commit:
SonarSource/sonar-scanner-vsts@956ba21#diff-3a4ea7e6eb2e6b2767e851d8f1b58b72
I am getting this error after the update yesterday
[ ] is sonarqube version 7.9.3 LTS supported?
[ ] is sonarqube version 8.9.x LTS supported?
The marketplace link indicates the following:
An extension that breaks your build whenever the quality gate in SonarQube failed. This plugin works with SonarQube extension for VSTS 4.x and SonarQube 6.x
As we are using sonar build break task in Azure CI past one hour we are getting below error message, kindly help us on this.
I've run below task in debug, kindly check.
##[debug]Using node path: /opt/Azure-BuildAgent/externals/node/bin/node
##[debug]agent.TempDirectory=/opt/Azure-BuildAgent/_work/_temp
##[debug]loading inputs and endpoints
##[debug]loading INPUT_SONARQUBE
##[debug]loading ENDPOINT_AUTH_c2056c3c-68dd-4298-9c16-1eb568e42d14
##[debug]loading ENDPOINT_AUTH_SCHEME_c2056c3c-68dd-4298-9c16-1eb568e42d14
##[debug]loading ENDPOINT_AUTH_PARAMETER_c2056c3c-68dd-4298-9c16-1eb568e42d14_USERNAME
##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
##[debug]loading SECRET_SONARQUBE_ENDPOINT
##[debug]loaded 8
##[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 ...
Finishing: Break build on quality gate failure
Hello, first of all thank you for the vsts extention.
It would be nice if you could not only get the status. There was a good plugin on the SonarQube Server side called QualityGate breaker. This just does not work any more for VSTS.
But it also printed a summery of the Conditions which are failed.
For Example:
New Major Issues: 3 > 0
Code Coverage on new code: 50 < 75
any chance of running npm audit fix
to upgrade your dependencies?
I submitted a PR for the one that doesn't auto-fix: microsoft/tfs-cli#444
Hello,
The build breaker task is all of a sudden failing with the following error. Not sure if a change to the Azure DevOps API caused the following but wanted to reach out to see if you had any insight.
Getting task report from file D:\AzDOAgents\Agent1_work\53.sonarqube\out.sonar\report-task.txt
Retrieving analysisId from https://<OUR_URL>/sonar/api/ce/task?id=AWyMCyPRF-FKoHTXr7-L
##[error]Unknown result from previous http request. The body is: [object Object]. Statuscode is 200
Retrieving quality gate report from https://<OUR_URL>/sonar/api/qualitygates/project_status?analysisId=undefined
##[error]Something went wrong! Got statuscode 404 and error null
##[error]Unknown result from previous http request. The body is: [object Object]. Statuscode is 404
##[error]Unhandled: Cannot read property 'status' of undefined
##[section]Finishing: Break build on quality gate failure
We have CI/CD, built on AzureDevops. Quality Gate Job with SonarCloud scan.
Everything was OK and it was working. Here is example of output:
==============================================================================
Task : SonarCloud build breaker
Description : Break the build when the quality gate fails.
Version : 2.1.2
Author : Simon de Lang
Help :
==============================================================================
Number of analyses in this build: 1
Summary of statusses: "ERROR"
##[error]The analysis did not pass the quality gate because because at least one analysis has has the status 'ERROR'. Attempting to fail the build!
Finishing: Break build on quality gate failure
Then 12.06.2023 I turned off build breaker (needed for testing)
And the problem is that when I turned it on back yesterday (14.06.2023), SonarCloud Build Breaker stopped to break builds when Sonar scan find something. So I checked the output of the build breaker step and found that it cannot see the scan result. Output of task is following:
==============================================================================
Task : SonarCloud build breaker
Description : Break the build when the quality gate fails.
Version : 2.1.2
Author : Simon de Lang
Help :
==============================================================================
Number of analyses in this build: 0
Summary of statusses:
Finishing: Break build on quality gate failure
What that could be?
The only difference I see is that version of SonarCloud task is different. In scans few days ago, SonarCloud Publish task version was 1.11.3. Now - it is 1.13.0
Here is also part of YAML used in our pipeline:
- task: SonarCloudAnalyze@1
displayName: 'SonarCloud: Code Analysis'
- task: SonarCloudPublish@1
displayName: 'SonarCloud: Publish Result'
- task: SimondeLang.sonarcloud-buildbreaker.sonar-buildbreaker.sonarcloud-buildbreaker@2
displayName: 'SonarCloud: Break build on quality gate failure'
condition: eq(variables['Build.Reason'], 'PullRequest')
inputs:
SonarCloud: 'SonarCloud'
organization: 'XXXXXXXXXXXXX'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.