user7769974
user7769974

Reputation:

SonarQube 6.7 LTS group permissions API doesn't working

I'm migrating SonarQube from 5.6 version to 6.7. I'm using SonarQube API with my Jenkins jobs and the problem is the API for groups permissions isn't working with 6.7 version...

I've tried manually with Postman (POST raw JSON) this :

{
    "groupName": "project-name-admin",
    "permission": "admin",
    "projectKey": "project-name"
}

The result returned is :

{
    "errors": [
        {
            "msg": "Group name or group id must be provided"
        }
    ]
}

And it's the same if I use :

{
    "groupId": 53,
    "permission": "admin",
    "projectKey": "project-name"
}

or

{
    "groupId": 53,
    "groupName": "project-name-admin",
    "permission": "admin",
    "projectKey": "project-name"
}

It's working with 6.5 verison and I've no idea where this problem may come from :(

@SonarQube developers team : can you fix thaaaat please ?

Upvotes: 6

Views: 537

Answers (2)

Prikkeldraad
Prikkeldraad

Reputation: 1375

This is a piece of code to assign a project to a gate, using authentication and post. Mind the body and content-type!

// format post, sonarqube only knows form encoded
def body = sprintf("gateId=%s&projectKey=%s", ["${gateId}", "${projectKey}"])

// post to associate project with gate
result = httpRequest (
    consoleLogResponseBody: true,
    authentication: '<My Jenkins Credential>', 
    contentType: 'APPLICATION_FORM',
    httpMode: 'POST', 
    ignoreSslErrors: true, 
    requestBody: "${body}", 
    url: "http://<sonarqube.url>/api/qualitygates/select"
)

Upvotes: 0

Teryk - SonarSource
Teryk - SonarSource

Reputation: 994

Send data as application/x-www-form-urlencoded or form-data. SonarQube Web API doesn't handle POST body in raw JSON format. See this question about Java ServletRequest to know more (Tomcat is used under the hood).

Upvotes: 3

Related Questions