Reputation: 3083
I'm using the github rest api to create repo environments:
https://docs.github.com/en/rest/reference/repos#create-or-update-an-environment
The api allows us to select deployment_branch_policy.custom_branch_policies: (boolean)
but I can't find a way of creating a deployment branch rule with a custom pattern, like you would do on the UI:
Is there any way of creating this through the REST api?
Many thanks
Upvotes: 3
Views: 356
Reputation: 186
After you create the env, you can add a branch policy by following the steps from their doc at https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28
something like so:
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment-branch-policies
Upvotes: 0
Reputation: 1214
It should be possible to do via the Deployment branch policies API:
The Deployment branch policies API allows you to specify custom name patterns that branches must match in order to deploy to an environment. The
deployment_branch_policy.custom_branch_policies
property for the environment must be set to true to use these endpoints. To update thedeployment_branch_policy
for an environment, see "Create or update an environment."For more information about restricting environment deployments to certain branches, see "Using environments for deployment."
Upvotes: 1