Trigger pipelines on forked pull requests with the API

By default, CircleCI will not build a pull request (PR) from a forked repository on your project. However, your team can enable this by visiting Project Settings>Advanced on your project and set the Build forked pull requests option to On.

Forked PRs built on CircleCI will appear to automatically have the branch name pull/x, where x is the PR number.

However, if you would like to trigger a pipeline on this branch with the API, you will have to use a slightly different branch name: pull/x/head.

So for example, you can trigger a pipeline with a POST request to our API as follows:

curl \
-u ${YOUR_CIRCLE_TOKEN}: \
-X POST --header "Content-Type: application/json" \
-d '{ "branch": "pull/${PR_BRANCH_NUM}/head" }' \
https://circleci.com/api/v2/project/{VCS}/{ORG}/{PROJECT}/pipeline

Replacing the following with the appropriate values:

YOUR_CIRCLE_TOKEN = Your CircleCI API token

PR_BRANCH_NUM = The pull request number, seen as the number in the branch as `pull/x`

VCS = gh or bb

ORG = VCS organization

PROJECT = VCS repository name

Was this article helpful?
0 out of 1 found this helpful

Comments

0 comments

Please sign in to leave a comment.