buildkite / feedback

Got feedback? Please let us know!
https://buildkite.com
25 stars 24 forks source link

Feature: Filter option to trigger pipeline only when a Github PR is open #283

Closed therealbnut closed 6 years ago

therealbnut commented 6 years ago

Some CI builds/pipelines only make sense when there's a pull-request. Unfortunately you can't make a pull request before you've pushed the changes and buildkite runs build on push.

For example:

I'd love to have something like Only build pull requests (mock):

screen shot 2017-10-19 at 8 29 58 am

It would fix many problems, and it would mean far fewer un-necessary builds, which is good for build times, and good for the environment 🐨.


This should be able to be implemented by checking if the BUILDKITE_PULL_REQUEST environment variable would be non-empty 🎉

~I suspect you already have the information you need to make this happen, as you link to open pull requests from your build UI (https://buildkite.com/org/pipeline/builds/1234).~

~You should be able to work this out by doing an extra call to GitHub's API to determine if there's any PRs that contain that commit. However if you don't want to incur that extra call there are some other options:~

~I imagine you know Github's hooks much better than me, but I looked into how feasible this might be.~

~It doesn't look like the Github push hook alone has the information you need, but you can probably ignore the push events that aren't preceded by a pull_request (action: opened).~

~You can determine that the commit is on that pull request by comparing the ref field on both events. If that is insufficient you can get the initial commit on the PR's "head" and link it with each push event's "before" commit hash.~


Related to:

therealbnut commented 6 years ago

We can get the behaviour we want by turning off "Skip pull request builds for existing commits", it does mean many unnecessary builds though. I'm closing this issue for now.

joechron commented 4 years ago

Would love to see this feature implemented. We have a lot of unnecessary builds.

rohansingh commented 4 years ago

Is this really the behavior you want? I think most projects will want to build on pull requests, and also on pushes to a master branch. You can achieve that by configuring the pipeline's branch filter to only build on pushes to master. Pull requests ignore that filter.

Alternatively, if you really truly only want to build on pull requests, you could try setting the branch filter to something like !* to not build on a push to any branch.

I haven't tested that filter pattern myself, but I think it should work. If it doesn't, you could always try setting the filter to something like random-prefix-you-never-use-for-an-actual-branch.