How do you trigger builds when a PR is merged?

What’s the event that one can use to trigger this behavior? Because I’m trying to build containers and push it to my repository but only if the PR get’s merged.

Is this something available to CE?

What’s the event that one can use to trigger this behavior?

When a pull request is merged GitHub sends a push hook to drone

Because I’m trying to build containers and push it to my repository but only if the PR get’s merged. Is this something available to CE?

Yes. This is how we publish the official drone image and all of the drone plugin images. Below is a snippet from one of our yaml files. You will see we use conditions to limit execution to push events, which are triggered when a pull request is merged.

pipeline:
  publish:
    image: plugins/docker
    repo: drone/drone
    secrets: [ docker_username, docker_password ]
    tag: [ latest ]
    when:
      branch: master
+     event: push
1 Like

@brad

Can you think of a situation where this wouldn’t get triggered? It builds the PRs normally, but when merging PRs and it wont start a build until I change something in that branch and push directly :confused:

Can you think of a situation where this wouldn’t get triggered

Nope, other than an issue with GitHub (webhook delivery outage, etc). GitHub will always trigger a push hook when you merge code. You can see a list of all webhooks that were delivered by github in your repository settings screen (in GitHub). Then you can look at your Drone server logs, which will always have an entry in the logs if a hook is ignored or fails to execute for any reason – every failure path is logged. If you don’t see anything in the logs, I would question whether or not the hook was delivered.

Thanks Brad. I checked the webhooks settings and it said there was a timeout. When I resent it, it worked. So probably something on my end.

Hi,
I think I had a similar issue: I wanted to get the information about what was the initial branch the PR was coming from, when the PR is being merged.
I then created a “push” pipeline, and created a script that gets information about the current push commit, especially if it is a PR merge, and if so, what was the initial branch.
As the Drone ‘git clone’ step only fetches information about the current branch being pushed, I went through the GitHub API…
I am not sure it is the simplest way to proceed, but still it works for me: drone-pr-merge.
Cheers

1 Like