Skip to content

create_webhook

create_webhook(
    project_name: ProjectName,
    *,
    config_overrides: Optional[CodeBuildClientConfig] = None,
    branch_filter: Optional[String] = None,
    filter_groups: Optional[FilterGroups] = None,
    build_type: Optional[WebhookBuildType] = None,
    manual_creation: Optional[WrapperBoolean] = None,
    scope_configuration: Optional[ScopeConfiguration] = None,
    pull_request_build_policy: Optional[PullRequestBuildPolicy] = None,
) -> CreateWebhookOutput

For an existing CodeBuild build project that has its source code stored in a GitHub or Bitbucket repository, enables CodeBuild to start rebuilding the source code every time a code change is pushed to the repository.

If you enable webhooks for an 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 CodeBuild. In the CodeBuild console, clear the Webhook box. For more information, see step 5 in Change a Build Project's Settings.

Parameters:

  • project_name (ProjectName) –

    The name of the CodeBuild project.

  • branch_filter (Optional[String], default: None ) –

    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 branchFilter is empty, then all branches are built.

    It is recommended that you use filterGroups instead of branchFilter.

  • filter_groups (Optional[FilterGroups], default: None ) –

    An array of arrays of WebhookFilter objects used to determine which webhooks are triggered. At least one WebhookFilter in the array must specify EVENT as its type.

    For a build to be triggered, at least one filter group in the filterGroups array must pass. For a filter group to pass, each of its filters must pass.

  • build_type (Optional[WebhookBuildType], default: None ) –

    Specifies the type of build this webhook will trigger.

    RUNNER_BUILDKITE_BUILD is only available for NO_SOURCE source 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 CodeBuild user guide.

  • manual_creation (Optional[WrapperBoolean], default: None ) –

    If manualCreation is true, CodeBuild doesn't create a webhook in GitHub and instead returns payloadUrl and secret values for the webhook. The payloadUrl and secret values in the output can be used to manually create a webhook within GitHub.

    manualCreation is only available for GitHub webhooks.

  • scope_configuration (Optional[ScopeConfiguration], default: None ) –

    The scope configuration for global or organization webhooks.

    Global or organization webhooks are only available for GitHub and Github Enterprise webhooks.

  • pull_request_build_policy (Optional[PullRequestBuildPolicy], default: None ) –

    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.

Raises:

Source code in docs_src/capo_codebuild/_services/code_build.py
def create_webhook(
    self,
    project_name: "capo_codebuild.types.project_name.ProjectName",
    *,
    config_overrides: Optional[CodeBuildClientConfig] = None,
    branch_filter: Optional["capo_codebuild.types.string.String"] = None,
    filter_groups: Optional[
        "capo_codebuild.types.filter_groups.FilterGroups"
    ] = None,
    build_type: Optional[
        "capo_codebuild.types.webhook_build_type.WebhookBuildType"
    ] = None,
    manual_creation: Optional[
        "capo_codebuild.types.wrapper_boolean.WrapperBoolean"
    ] = None,
    scope_configuration: Optional[
        "capo_codebuild.types.scope_configuration.ScopeConfiguration"
    ] = None,
    pull_request_build_policy: Optional[
        "capo_codebuild.types.pull_request_build_policy.PullRequestBuildPolicy"
    ] = None,
) -> "capo_codebuild.types.create_webhook_output.CreateWebhookOutput":
    """<p>For an existing CodeBuild build project that has its source code stored in a GitHub or Bitbucket repository, enables CodeBuild to start rebuilding the source code every time a code change is pushed to the repository.</p> <important> <p>If you enable webhooks for an 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 CodeBuild. In the CodeBuild console, clear the Webhook box. For more information, see step 5 in <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/change-project.html#change-project-console">Change a Build Project's Settings</a>.</p> </important>

    Args:
        project_name: <p>The name of the CodeBuild project.</p>
        branch_filter: <p>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 <code>branchFilter</code> is empty, then all branches are built.</p> <note> <p>It is recommended that you use <code>filterGroups</code> instead of <code>branchFilter</code>. </p> </note>
        filter_groups: <p>An array of arrays of <code>WebhookFilter</code> objects used to determine which webhooks are triggered. At least one <code>WebhookFilter</code> in the array must specify <code>EVENT</code> as its <code>type</code>. </p> <p>For a build to be triggered, at least one filter group in the <code>filterGroups</code> array must pass. For a filter group to pass, each of its filters must pass. </p>
        build_type: <p>Specifies the type of build this webhook will trigger.</p> <note> <p> <code>RUNNER_BUILDKITE_BUILD</code> is only available for <code>NO_SOURCE</code> source type projects configured for Buildkite runner builds. For more information about CodeBuild-hosted Buildkite runner builds, see <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/sample-runner-buildkite.html">Tutorial: Configure a CodeBuild-hosted Buildkite runner</a> in the <i>CodeBuild user guide</i>.</p> </note>
        manual_creation: <p>If manualCreation is true, CodeBuild doesn't create a webhook in GitHub and instead returns <code>payloadUrl</code> and <code>secret</code> values for the webhook. The <code>payloadUrl</code> and <code>secret</code> values in the output can be used to manually create a webhook within GitHub.</p> <note> <p> <code>manualCreation</code> is only available for GitHub webhooks.</p> </note>
        scope_configuration: <p>The scope configuration for global or organization webhooks.</p> <note> <p>Global or organization webhooks are only available for GitHub and Github Enterprise webhooks.</p> </note>
        pull_request_build_policy: <p>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.</p>

    Raises:
        capo_codebuild.errors.invalid_input_exception.InvalidInputException: <p>The input value that was provided is not valid.</p>
        capo_codebuild.errors.o_auth_provider_exception.OAuthProviderException: <p>There was a problem with the underlying OAuth provider.</p>
        capo_codebuild.errors.resource_already_exists_exception.ResourceAlreadyExistsException: <p>The specified Amazon Web Services resource cannot be created, because an Amazon Web Services resource with the same settings already exists.</p>
        capo_codebuild.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified Amazon Web Services resource cannot be found.</p>
        capo_codebuild.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_codebuild.types.create_webhook_input.CreateWebhookInput]",
    ) -> OperationResponse[
        "capo_codebuild.types.create_webhook_output.CreateWebhookOutput"
    ]:
        import capo_codebuild._operations.code_build_20161006.create_webhook

        output, http_response = (
            capo_codebuild._operations.code_build_20161006.create_webhook.create_webhook(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateWebhook")
    )
    input_: capo_codebuild.types.create_webhook_input.CreateWebhookInput = {
        "project_name": project_name
    }
    if branch_filter is not None:
        input_["branch_filter"] = branch_filter
    if filter_groups is not None:
        input_["filter_groups"] = filter_groups
    if build_type is not None:
        input_["build_type"] = build_type
    if manual_creation is not None:
        input_["manual_creation"] = manual_creation
    if scope_configuration is not None:
        input_["scope_configuration"] = scope_configuration
    if pull_request_build_policy is not None:
        input_["pull_request_build_policy"] = pull_request_build_policy

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output