adnanh / webhook

webhook is a lightweight incoming webhook server to run shell commands
MIT License
10.38k stars 832 forks source link

Use as a webhook proxy #184

Open mattwwarren opened 7 years ago

mattwwarren commented 7 years ago

I am attempting to use webhook as a public interface to our services hosted on a private network. Currently, I am running into an issue where I cannot create jenkins webhooks from Bitbucket for a few reasons.

  1. The URL used by the bitbucket webhook varies based on which jenkins job we wish to trigger This causes a few issues on the webhook side:

    • I do not believe it should be the responsibility of the user to enumerate all possible job urls. This becomes a maintenance nightmare
    • Even if it was the responsibility of the user, webhook does not allow slashes in the url id
    • Webhook does not currently allow for wildcards in url ids
  2. There is no easy (or documented way) to pass the exact input from a request to webhook on to a backend service

    • Perhaps I am mistaken in using webhook in such a way but the program provides a little extra validation and flexibility over using a straight up proxy.
  3. If I workaround 2 by using a straight up proxy, there are other documented issues with placing a proxy in front of webhook

    • Primarily, #152

Sadly, my go skills are as near to nothing as makes no odds but I am willing to attempt tackling some of these points with some guidance.

adnanh commented 7 years ago

Glad you like the webhook, however it sounds to me that you would be much better off by using the proper Jenkins plugin for the described task, expose the Jenkins directly and avoid webhook altogether.

There is a way to pass the payload, query and headers, it's documented in the wiki under the Special cases.

adnanh commented 7 years ago

As for the webhook based solution, solving #152 would be the proper way to handle this case, but I just don't have the time to do that :-(

mattwwarren commented 7 years ago

Sorry, I should have been more clear in point 2. entire-payload works for my case but the issue remains in how to pass that in a command. I think I can use curl https://jenkins/jenkins/ but then I have to add part of the URI as constructed by Bitbucket (e.g. job/my-tests/build)

What are your thoughts on allowing regex matching in ids? I understand that all things take time but I am willing to learn/help to get up to speed on go, which is increasing in use at $WORK

adnanh commented 7 years ago

Are you using the curl directly as a command for webhook? If so, you should try using a shell script to do the preprocessing, construction and invocation of the proper curl $ENDPOINT command based on the payload. If you could provide sample payload and resulting endpoints that should be invoked, maybe I can help you with the writing of the "wrapper" script.

adnanh commented 7 years ago

In that case you would have only one hook.

mattwwarren commented 7 years ago

I was thinking curl was the easiest way to do the passthrough. But that still doesn't solve the problem of bitbucket requesting https://webhook/jenkins/job/my-tests/build

I cannot seem to create a rule with:

    "id": "jenkins/job/my-tests/build",

And a rule like:

    "id": "jenkins",

would not match the request. Is this right?

adnanh commented 7 years ago

Correct. Is there no way to tell bitbucket to hit another url?