Home > Back-end >  AWS CodeBuild webhook trigers when it shoudn't start
AWS CodeBuild webhook trigers when it shoudn't start

Time:04-28

I have the following setup of codebuild's webhook:

resource "aws_codebuild_webhook" "apply" {
  project_name = aws_codebuild_project.codebuild-apply.name
  build_type   = "BUILD"
  filter_group {
    filter {
      type    = "EVENT"
      pattern = "PUSH"
    }
    filter {
      type    = "FILE_PATH"
      pattern = "environments/test/*"
    }
    filter {
      type    = "HEAD_REF"
      pattern = "master"
    }
  }
}

Purpose is to run it only when changes on master branch are done. Currently this webhook starts buildspec when changes are done in environments/test/ on every branch not only master branch.

What is wrong and how to setup it correctly?

CodePudding user response:

according to https://docs.aws.amazon.com/codebuild/latest/userguide/github-webhook.html the right format for the pattern of your filter of type HEAD_REF is ^refs/heads/master$.

I only now realized, that you use terraform. Can you try with

filter {
      type                    = "HEAD_REF"
      pattern                 = "refs/heads/master"
      
    }
  • Related