Overview
You set up GitHub App triggers so that opening a pull request builds, and so that pushes to a pull request build. A draft pull request gets one pipeline when it is opened. Later commits to the draft do not start a pipeline. Pipelines resume after you mark the pull request ready for review and push again.
Trigger options and draft PRs
The GitHub App trigger options handle drafts differently:
UI option | API and Terraform preset | Draft PRs |
PR opened |
| Runs when the PR is opened, including drafts. Does not run on later pushes. |
Pushes to open non-draft PRs |
| Skips drafts. Runs on pushes only once the PR is ready for review. |
PR opened or pushed to, default branch and tag pushes |
| Runs for drafts on open and on every push. Also runs on pushes to the default branch, tag pushes, and reopened PRs. |
Solution
Use one trigger with the preset PR opened or pushed to, default branch and tag pushes (only-build-prs) instead of the separate PR triggers.
In the CircleCI web app, open Project Settings for the project, then Project Setup.
Edit the GitHub trigger on the pipeline, or add a new one, and set Run on to PR opened or pushed to, default branch and tag pushes.
Remove the separate PR opened, PR push, and default branch push triggers. Keeping them as well creates duplicate pipelines.
If you manage triggers with Terraform, set the preset on a single trigger:
resource "circleci_trigger" "pull_requests" {
# ... project and pipeline settings ...
event_preset = "only-build-prs"
}Run terraform plan first to see what will change.
Tag pushes
This preset also runs when a tag is pushed. If none of your workflows are set to run for tags, the pipeline is created with the message "No workflows for this pipeline". No jobs run.
Do not add pipeline.git.tag == "" to a workflow when clause to skip tags. It also stops pull request pipelines from running.
Keep drafts out of one workflow
If you want most workflows to run for drafts but not a specific one, add a condition on the draft pipeline value to that workflow. It still runs the workflow for pushes and for API or manual runs:
workflows:
full-checks:
when: pipeline.event.name == "api" or pipeline.event.name == "push" or (pipeline.event.name == "pull_request" and pipeline.event.github.pull_request.draft == false)
jobs:
- build
Verification
Open a draft pull request. A pipeline runs.
Push another commit to the draft pull request. A second pipeline runs.
Push a commit to the default branch. A pipeline runs.
