Sonar webhook data 'stripped' in Jenkins - jenkins

I'm using Jenkins DSL multibranch build paired with Sonarqube community + Community branch plugin.
So far, I was using waitForQualityGate to get Sonar's quality gate results back in Jenkins and it was working as expected. I was checking qg.status to display Sonar status but, now I tried to include more detailed info (list of failed checks) on my job page.
Problem is that, on Jenkins side, JSON printout of waitForQualityGate is just:
{"status":"ERROR"}
When I check on Sonar side, I see that hook is executed with expected payload:
{
"serverUrl": "http://localhost:9000",
"taskId": "AXGhfNdNVsTZztVdmx-_",
"status": "SUCCESS",
"analysedAt": "2020-04-22T10:43:26+0000",
"changedAt": "2020-04-22T10:43:26+0000",
"project": {
"key": "XXXXXX",
"name": "XXXXXX",
"url": "http://localhost:9000/dashboard?id=XXXXXX"
},
"branch": {
"name": "branch_name",
"type": "SHORT",
"isMain": false,
"url": "http://localhost:9000/project/issues?branch=branch_name&id=XXXXXX&resolved=false"
},
"qualityGate": {
"name": "MY_quality_gate",
"status": "ERROR",
"conditions": [
{
"metric": "new_reliability_rating",
"operator": "GREATER_THAN",
"value": "1",
"status": "OK",
"errorThreshold": "1"
},
{
"metric": "new_security_rating",
"operator": "GREATER_THAN",
"value": "1",
"status": "OK",
"errorThreshold": "1"
},
{
"metric": "new_maintainability_rating",
"operator": "GREATER_THAN",
"value": "3",
"status": "ERROR",
"errorThreshold": "1"
},
{
"metric": "new_coverage",
"operator": "LESS_THAN",
"value": "100.0",
"status": "OK",
"errorThreshold": "90"
}
]
},
"properties": {}
}
Please note that payload have status=SUCCESS and qualityGate.status=ERROR while, on Jenkins side, it defines status=ERROR and no qualityGate node at all?
Within job console log I can find:
[Pipeline] waitForQualityGate
Checking status of SonarQube task 'AXGh4vchVsTZztVdmx_J' on server 'SonarQube'
SonarQube task 'AXGh4vchVsTZztVdmx_J' status is 'SUCCESS'
SonarQube task 'AXGh4vchVsTZztVdmx_J' completed. Quality gate is 'ERROR'
I can not find any settings on Jenkins side that could be related to this issue (standard settings are set and normally working).
Version used:
Jenkins: 2.150.1
SonarQube Scanner plugin: 2.8.1
Sonarqube: 7.7.0.23042
Thx in advance for any tips or suggestions...

Related

Pull Request Statuses - Added custom properties to a status aren't getting persisted by TFS

We are operating a TFS 2018 Update 2 in our enviroment.
We are sending the example json found here to our server and it is getting accepted successfully:
{
"properties": {
"sampleId": 7,
"customInfo": "Custom status information",
"startedDateTime": {
"$type": "System.DateTime",
"$value": "2017-09-19T14:50:26.7410146Z"
},
"weight": {
"$type": "System.Double",
"$value": 1.75
},
"bytes": {
"$type": "System.Byte[]",
"$value": "dGhpcyBpcyBzYW1wbGUgYmFzZTY0IGVuY29kZWQgc3RyaW5n"
},
"globalId": {
"$type": "System.Guid",
"$value": "1e788cb9-9d3d-4dc6-ac05-822092d17f90"
}
},
"state": "succeeded",
"description": "Sample status succeeded",
"context": {
"name": "sample-status-1",
"genre": "vsts-samples"
},
"targetUrl": "http://fabrikam-fiber-inc.com/CI/builds/1"
}
But the response doesn't look like in the documentation. Instead it looks like this:
{
"id": 6,
"state": "succeeded",
"description": "Sample status succeeded",
"context": {
"name": "sample-status-1",
"genre": "vsts-samples"
},
"creationDate": "2019-12-11T16:14:05.0574648Z",
"updatedDate": "2019-12-11T16:14:05.0574648Z",
"createdBy": {
"displayName": "...",
"url": "https://.../_apis/Identities/0b85e078-130d-4cb8-a450-17c5c7efccec",
"_links": {
"avatar": {
"href": "https://.../_api/_common/identityImage?id=0b85e078-130d-4cb8-a450-17c5c7efccec"
}
},
"id": "0b85e078-130d-4cb8-a450-17c5c7efccec",
"uniqueName": "...",
"imageUrl": "https://.../_api/_common/identityImage?id=0b85e078-130d-4cb8-a450-17c5c7efccec"
},
"targetUrl": "http://fabrikam-fiber-inc.com/CI/builds/1",
"_links": {
"self": {
"href": "https://.../_apis/git/repositories/35fe73eb-7af1-4bba-bf04-545611fcac1d/pullRequests/58/statuses/6"
},
"repository": {
"href": "https://.../_apis/git/repositories/35fe73eb-7af1-4bba-bf04-545611fcac1d"
}
}
}
The properties are gone. What could be wrong?
Could it be a somehow completely missleading documentation?
To troubleshoot your issue, please check the following items:
Check whether the Status updated on the pull request after running the POST request.
Press F12 in your browser, and send the POST request to check the statuses to see whether you can get properties in the response body.
Check your TFS edition by going to Administration Console -- Application Tier, or checking the About on the web portal. The issue can not be reproduced in TFS 2018.2 on our side.

Get Log for each Jenkins pipeline stage

Anyone know how I can get the separate logs (for each pipeline stage) as the Blue Ocean shows. I need to attach them to Jira but I can not find them.
Any idea?
I'm doing the same thing with the global pipeline library I'm building. This is good for cases where you just want to email the logs of a particular failed stage. Here's how hope it helps. On the sample pipeline below a job named test is executed once (build #1)
pipeline {
agent any
stages{
stage("Compile") {
steps {
script {
echo "Compiling..."
}
}
}
stage("Test") {
steps {
script {
echo "Testing..."
}
}
}
stage("Build") {
steps {
script {
echo "Building..."
}
}
}
}
}
Access the API to see execution details. Notice that each object of this JSON includes the attributes id and result.
http://localhost:8080/blue/rest/organizations/jenkins/pipelines/test/runs/1/nodes/
[
{
*snip*
"actions": [],
"displayDescription": null,
"displayName": "Compile",
"durationInMillis": 341,
"id": "6",
"input": null,
"result": "SUCCESS",
"startTime": "2018-11-24T18:14:16.196+0800",
"state": "FINISHED",
"type": "STAGE",
"causeOfBlockage": null,
"edges": [
{
"_class": "io.jenkins.blueocean.rest.impl.pipeline.PipelineNodeImpl$EdgeImpl",
"id": "15",
"type": "STAGE"
}
],
"firstParent": null,
"restartable": true
},
{
*snip*
"actions": [],
"displayDescription": null,
"displayName": "Test",
"durationInMillis": 246,
"id": "15",
"input": null,
"result": "SUCCESS",
"startTime": "2018-11-24T18:14:16.693+0800",
"state": "FINISHED",
"type": "STAGE",
"causeOfBlockage": null,
"edges": [
{
"_class": "io.jenkins.blueocean.rest.impl.pipeline.PipelineNodeImpl$EdgeImpl",
"id": "24",
"type": "STAGE"
}
],
"firstParent": "6",
"restartable": true
},
{
*snip*
"actions": [],
"displayDescription": null,
"displayName": "Build",
"durationInMillis": 270,
"id": "24",
"input": null,
"result": "SUCCESS",
"startTime": "2018-11-24T18:14:17.188+0800",
"state": "FINISHED",
"type": "STAGE",
"causeOfBlockage": null,
"edges": [],
"firstParent": "15",
"restartable": true
}
]
Use result to check the status of a stage (SUCCESS, FAILED, ABORTED, etc...)
Use id to get into a particular stage, for this example the logs of Test stage which has an id of 15.
http://localhost:8080/blue/rest/organizations/jenkins/pipelines/test/runs/1/nodes/15/log/
Testing...
you can find the rest api document through this url:
https://github.com/jenkinsci/blueocean-plugin/tree/master/blueocean-rest
still need to notice this in their document.
The Blue Ocean REST API is a "private API" designed for the Blue Ocean user interface.
It may change without notice at any time.

How to display "Area path" in VSTS build task input PickList?

I need to display the the "Area path" in a VSTS Build task input PickList, so that I can retrieve the user selected "Area path" value from my build task and set it in a work item generated by the build task. Is this possible with existing VSTS API? If so how to do this?
I think this is done in Copy Files task in Utilty section.
Thanks in advance.
Yes, it is. You can add following section in task.josn file to achieve this:
"inputs": [
{
"name": "rootArea",
"type": "pickList",
"label": "rootArea",
"defaultValue": "",
"required": false,
"helpMarkDown": "Select the root area.",
"properties": {
"DisableManageLink": "True"
}
},
{
"name": "childArea",
"type": "pickList",
"label": "childArea",
"defaultValue": "",
"required": false,
"helpMarkDown": "Select the child area.",
"properties": {
"DisableManageLink": "True"
}
}
],
"sourceDefinitions": [
{
"target": "rootArea",
"endpoint": "/$(system.teamProject)/_apis/wit/classificationNodes/areas?$depth=2&api-version=1.0",
"selector": "jsonpath:$.name",
"keySelector": "jsonpath:$.name",
"authKey": "tfs:teamfoundation"
},
{
"target": "childArea",
"endpoint": "/$(system.teamProject)/_apis/wit/classificationNodes/areas?$depth=2&api-version=1.0",
"selector": "jsonpath:$.children[*].name",
"keySelector": "jsonpath:$.children[*].name",
"authKey": "tfs:teamfoundation"
}
],
And you will get the build task like this:
However, due to data structure in the response of classification nodes api, you have to add more inputs when there are more level of child areas.

Mercurial Bitbucket jenkins plugin 500 error

I'm trying to configure bitbucket (Mercurial) and Jenkins.
I installed the Bitbucket Jenkins plugin:
https://wiki.jenkins-ci.org/display/JENKINS/BitBucket+Plugin
on Bitbucket, I configure a new webhook:
http://X.X.X.X:8080/jenkins/bitbucket-hook/
and I can see that a called is done everytime I pushed my commits:
Event: repo:push
Details: 2 minutes ago
Error: 500
On Jenkins Logs I can see that a JSON is received:
Received commit hook notification for
{
"scm": "hg",
"uuid": "{6c2bcf03-9371-4a6b-bef4-XXXXXXXX}",
"is_private": true,
"full_name": "XXXXXXX/XXXXXXdy09",
"name": "XXXX-dy09",
"type": "repository",
"links": {
"html": {
"href": "https://bitbucket.org/XXXXXXX/YYYYYYs-dy09"
},
"avatar": {
"href": "https://bitbucket.org/XXXXXXXXXX/YYYYYYYYYdy09/avatar/32/"
},
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/XXXXXXXXXX/YYYYYYYYYYYdy09"
}
},
"owner": {
"display_name": "XXXXXXX",
"uuid": "{bca96c46-239a-4dd7-885e-XXXXXXX}",
"links": {
"html": {
"href": "https://bitbucket.org/XXXXXXXXXXX/"
},
"avatar": {
"href": "https://bitbucket.org/account/XXXXXXXXXX/avatar/32/"
},
"self": {
"href": "https://api.bitbucket.org/2.0/users/XXXXXXXXXXXX"
}
},
"username": "XXXXXXXXXXX",
"type": "user"
}
}
but nothing is happening, any job is triggered.
Jenkins Job conf:
Any idea why my job is not triggered?
Thx in advance
ok, I'm going to ask my own asnwer.
it seems Mercurial is not supported at this moment.
in the following link:
https://github.com/jenkinsci/bitbucket-plugin/blob/master/src/main/java/com/cloudbees/jenkins/plugins/BitbucketJobProbe.java
you could see:
if ("git".equals(scm)) {
//more code
} else {
// TODO hg
throw new UnsupportedOperationException("Unsupported SCM type " + scm);
}
so, not possible using the bitbucket plugin.
there are many workarounds you can find on internet.

Jenkins Bitbucket Plugin - Cannot parse POST data

Sending a POST request to /jenkins/bitbucket-hook causes a 500 error:
javax.servlet.ServletException: net.sf.json.JSONException: A JSONObject text must begin with '{' at character 0 of
Regardless of the content type, or body data.
The body data being sent is that outlined by Bitbucket:
{
"canon_url": "https://bitbucket.org",
"commits": [
{
"author": "marcus",
"branch": "master",
"files": [
{
"file": "somefile.py",
"type": "modified"
}
],
"message": "Added some more things to somefile.py\n",
"node": "620ade18607a",
"parents": [
"702c70160afc"
],
"raw_author": "Marcus Bertrand <marcus#somedomain.com>",
"raw_node": "620ade18607ac42d872b568bb92acaa9a28620e9",
"revision": null,
"size": -1,
"timestamp": "2012-05-30 05:58:56",
"utctimestamp": "2012-05-30 03:58:56+00:00"
}
],
"repository": {
"absolute_url": "/marcus/project-x/",
"fork": false,
"is_private": true,
"name": "Project X",
"owner": "marcus",
"scm": "git",
"slug": "project-x",
"website": "https://atlassian.com/"
},
"user": "marcus"
}
Jenkins is the most up to date version, along with the Bitbucket plugin.
Update: I have used the data directly taken from BitBucket.
http://www.posttestserver.com/data/2015/05/20/sb/02.50.32555038623
I think I have answered my own question.
For me to get rid of that error I just had to add a trailing slash to the url... Something so simple worked for me. Might be worth others trying it too.

Resources