Webhook: Unable to extract data from GitHub webhook payload

Created on 6 Jun 2017  路  6Comments  路  Source: adnanh/webhook

Hi, I'm using the following version of webhook in a CentOS container:

  • webhook version 2.6.4
  • CentOS Linux release 7.3.1611 (Core)

My configuration file is based on the GitHub example shown in the wiki:

[
  {
    "id": "test",
    "execute-command": "/usr/local/bin/test.sh",
    "command-working-directory": "/tmp",
    "pass-arguments-to-command": [
        {"source": "payload", "name": "ref"},
        {"source": "payload", "name": "repository.name"}
    ]
  }
]

The test script being executed :

#!/bin/sh -e

echo ""
echo "Ref:" $1
echo "Repository:" $2

I've set up a GitHub webhook that only sends the push event. I've pasted just the relevant data from a payload that GitHub logged on their end:

{
  "ref": "refs/heads/master",
  "repository": {
    "name": "test"
  }
}

Webhook however complains that it can't access the above data in the payload delivered by GitHub:

/opt/webhook-linux-amd64/webhook -hooks /etc/webhook/hooks.json -port 9000 -verbose
[webhook] 2017/06/06 18:33:04 version 2.6.4 starting
[webhook] 2017/06/06 18:33:04 setting up os signal watcher
[webhook] 2017/06/06 18:33:04 attempting to load hooks from /etc/webhook/hooks.json
[webhook] 2017/06/06 18:33:04 found 1 hook(s) in file
[webhook] 2017/06/06 18:33:04   loaded: test
[webhook] 2017/06/06 18:33:04 serving hooks on http://0.0.0.0:9000/hooks/{id}
[webhook] 2017/06/06 18:33:04 os signal watcher ready
[webhook] 2017/06/06 18:34:19 incoming HTTP request from 10.0.2.2:47633
[webhook] 2017/06/06 18:34:19 test got matched
[webhook] 2017/06/06 18:34:19 test hook triggered successfully
[webhook] 2017/06/06 18:34:19 2017-06-06T18:34:19Z | 200 |       3.904615ms | <ip-address>:9000 | POST /hooks/test
[webhook] 2017/06/06 18:34:19 error extracting command arguments: couldn't retrieve argument for {Source:payload Name:ref EnvName:}
[webhook] 2017/06/06 18:34:19 error extracting command arguments: couldn't retrieve argument for {Source:payload Name:repository.name EnvName:}
[webhook] 2017/06/06 18:34:19 executing /usr/local/bin/test.sh (/usr/local/bin/test.sh) with arguments ["/usr/local/bin/test.sh" "" ""] and environment [] using /tmp as cwd
[webhook] 2017/06/06 18:34:19 command output:
Ref:
Repository:

[webhook] 2017/06/06 18:34:19 finished handling test

I haven't been able to figure out what I'm overlooking here 馃槙

Most helpful comment

Please ignore all of the above, I was using the wrong data format for the payload 馃槾

All 6 comments

Please ignore all of the above, I was using the wrong data format for the payload 馃槾

Hehe, happy hacking!

@avtar I have the exact same problem, could you share how you fixed it?

@avtar your comment about wrong data format gave me the hint, adding -H "Content-type: application/json" to my curl test requests did the trick, thanks!

Facing the same issue, while calling curl -X POST http://0.0.0.0:9000/hooks/redeploy-webhook -H "Content-Type: application/json" -d @data.json and data.json contains:

{
  "host": "hostname",
  "service": {
    "name": "serviceName"
  }
}

hooks.json file looks like:

[
  {
    "id": "redeploy-webhook",
    "execute-command": "/var/scripts/redeploy.sh",
    "command-working-directory": "/var/webhook",
    "pass-arguments-to-command":[
        {"source": "payload",
         "name": "service.name"}
]
  }
]

and redeploy.sh looks like :

#!/bin/bash
...
echo $1
....

Nothing seems to be printed in the output.
Is there something that I missed?

Never mind, I had to restart the service so the changes I made to hooks.json could take effect. Works like a charm now.

Was this page helpful?
0 / 5 - 0 ratings