How to use the REST api to set the webhook value without using JSON

web_api
webhooks

(David Karr) #1

I have a need to use the settings api to get the “sonar.webhooks.project” value, for a particular project. I then need to set that value into a different (but related) project.

I have no trouble getting the value.

If I had no restrictions, setting the value in the other project would also be simple. Unfortunately, the straightforward way to do this requires outputting JSON, and it looks like I’m not going to be allowed to do that in the normal way (I could simply hardcode a json string, but that’s not something I can live with). The issue is sandbox restrictions in the Jenkins pipeline script. All the paths that I’ve tried to take that require generating JSON from an object are either hitting script restrictions (which are not going to be approved), or just bugs in Jenkins pipeline steps (writeJSON throws known exception).

I’d really like to figure out how to use the “/settings/set” api in a way that doesn’t require using JSON. I had initially tried using the “fieldValues” parameter with JSON, but as I said, I have unreasonable obstacles down that path. I thought perhaps I could somehow use the “value” parameter instead, but the problem is the webhook value is a pair of values, a “Name” and “URL”.

Is there some way I can use the plain “value” parameter so I can set the webhook, without using JSON?


(Julien Lancelot) #2

Hi David,

Starting SonarQube 7.1, there are some dedicated web services to configure webhook : api/webhooks.

Regards


(David Karr) #3

Good to know. I may just get to use that someday. In the meantime, I have to implement a solution. I concluded that the mechanisms I’m restricted to for generating JSON are just too painful to use, so I ended up just writing a hardcoded Gstring containing the short JSON string I need to generate, with the “name” and “url” expressions for the webhook. This is a reasonable compromise, which also works.