简体   繁体   中英

Bitbucket webhook not sending payload

I'm new to webhooks and trying to do automated deployment to my website whenever I push to my repo.

I set up the webhook on my bitbucket repo to a URL which contains a simple php script:

if(isset($_POST['payload'])) {
    logMsg("Got stuff\n");
} else {
    logMsg("No stuff\n");
}

After I push to my repo, the webhook will request the script fine but no payload is sent. My log file will always say "No stuff".

What am I missing?

The new Bitbucket webhooks send the payload in the request body , not in the request headers as the previous "Services" did. So to access the payload you must read the request body like this :

$payload = file_get_contents('php://input');

or like that:

$payload = stream_get_contents(STDIN);

Et voilà !

BitBucket webhook changed recently (June 2015) .

The new event payload doc refers to a tutorial page whose example does not test for payload.
See atlassianlabs/webhook-listener and its listener.py (python, but the idea would be the same for php)

@app.route('/webhook', methods=['GET', 'POST'])
def tracking():  
    if request.method == 'POST':
        data = request.get_json()

It tries directly to decode json. If that json data were to be empty,... that would mean no payload.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM