CreateWebhook
For an existing AWS CodeBuild build project that has its source code stored in a GitHub or Bitbucket repository, enables AWS CodeBuild to start rebuilding the source code every time a code change is pushed to the repository.
Important
If you enable webhooks for an AWS CodeBuild project, and the project is used as a build step in CodePipeline, then two identical builds are created for each commit. One build is triggered through webhooks, and one through CodePipeline. Because billing is on a per-build basis, you are billed for both builds. Therefore, if you are using CodePipeline, we recommend that you disable webhooks in AWS CodeBuild. In the AWS CodeBuild console, clear the Webhook box. For more information, see step 5 in Change a Build Project's Settings.
Request Syntax
{
"branchFilter": "string",
"buildType": "string",
"filterGroups": [
[
{
"excludeMatchedPattern": boolean,
"pattern": "string",
"type": "string"
}
]
],
"manualCreation": boolean,
"projectName": "string",
"pullRequestBuildPolicy": {
"approverRoles": [ "string" ],
"requiresCommentApproval": "string"
},
"scopeConfiguration": {
"domain": "string",
"name": "string",
"scope": "string"
}
}
Request Parameters
For information about the parameters that are common to all actions, see Common Parameters.
The request accepts the following data in JSON format.
Note
In the following list, the required parameters are described first.
- projectName
-
The name of the AWS CodeBuild project.
Type: String
Length Constraints: Minimum length of 2. Maximum length of 150.
Pattern:
[A-Za-z0-9][A-Za-z0-9\-_]{1,149}Required: Yes
- branchFilter
-
A regular expression used to determine which repository branches are built when a webhook is triggered. If the name of a branch matches the regular expression, then it is built. If
branchFilteris empty, then all branches are built.Note
It is recommended that you use
filterGroupsinstead ofbranchFilter.Type: String
Required: No
- buildType
-
Specifies the type of build this webhook will trigger.
Note
RUNNER_BUILDKITE_BUILDis only available forNO_SOURCEsource type projects configured for Buildkite runner builds. For more information about CodeBuild-hosted Buildkite runner builds, see Tutorial: Configure a CodeBuild-hosted Buildkite runner in the AWS CodeBuild user guide.Type: String
Valid Values:
BUILD | BUILD_BATCH | RUNNER_BUILDKITE_BUILDRequired: No
- filterGroups
-
An array of arrays of
WebhookFilterobjects used to determine which webhooks are triggered. At least oneWebhookFilterin the array must specifyEVENTas itstype.For a build to be triggered, at least one filter group in the
filterGroupsarray must pass. For a filter group to pass, each of its filters must pass.Type: Array of arrays of WebhookFilter objects
Required: No
- manualCreation
-
If manualCreation is true, CodeBuild doesn't create a webhook in GitHub and instead returns
payloadUrlandsecretvalues for the webhook. ThepayloadUrlandsecretvalues in the output can be used to manually create a webhook within GitHub.Note
manualCreationis only available for GitHub webhooks.Type: Boolean
Required: No
- pullRequestBuildPolicy
-
A PullRequestBuildPolicy object that defines comment-based approval requirements for triggering builds on pull requests. This policy helps control when automated builds are executed based on contributor permissions and approval workflows.
Type: PullRequestBuildPolicy object
Required: No
- scopeConfiguration
-
The scope configuration for global or organization webhooks.
Note
Global or organization webhooks are only available for GitHub and Github Enterprise webhooks.
Type: ScopeConfiguration object
Required: No
Response Syntax
{
"webhook": {
"branchFilter": "string",
"buildType": "string",
"filterGroups": [
[
{
"excludeMatchedPattern": boolean,
"pattern": "string",
"type": "string"
}
]
],
"lastModifiedSecret": number,
"manualCreation": boolean,
"payloadUrl": "string",
"pullRequestBuildPolicy": {
"approverRoles": [ "string" ],
"requiresCommentApproval": "string"
},
"scopeConfiguration": {
"domain": "string",
"name": "string",
"scope": "string"
},
"secret": "string",
"status": "string",
"statusMessage": "string",
"url": "string"
}
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
Errors
For information about the errors that are common to all actions, see Common Errors.
- InvalidInputException
-
The input value that was provided is not valid.
HTTP Status Code: 400
- OAuthProviderException
-
There was a problem with the underlying OAuth provider.
HTTP Status Code: 400
- ResourceAlreadyExistsException
-
The specified AWS resource cannot be created, because an AWS resource with the same settings already exists.
HTTP Status Code: 400
- ResourceNotFoundException
-
The specified AWS resource cannot be found.
HTTP Status Code: 400
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: