aws-codebuildgithub-webhook

CodeBuild is building all commits to my destination branch. What is the correct way to configure builds on a specific branch?


In SourceVersion: ${BranchName} is set in the CodeBuild project. I thought that would limit the scope of all Push & Pull Request to ${BranchName} destination branch only.But apparently not. I am seeing every commit on every branch trigger the GitHub webhook to CodeBuild and cause it to build every commit! Not what I wanted.

So then in filters I tried to specify:

    Triggers:
        Webhook: true
        FilterGroups:
          - - Type: EVENT
              Pattern: PULL_REQUEST_MERGED
            - Type: BASE_REF
              Pattern: !Sub "refs/heads/${BranchName}$"
              ExcludeMatchedPattern: false
            - Type: FILE_PATH
              Pattern: ^webserver/               
          - - Type: EVENT
              Pattern: PUSH
            - Type: HEAD_REF
              Pattern: !Sub "refs/heads/${BranchName}$"
              ExcludeMatchedPattern: false                            
            - Type: FILE_PATH
              Pattern: ^webserver/     

With this now no builds are triggered. The GitHub webhooks gets a response from CodeBuild: No build triggered for specified payload. Clearly the filters do not work as documented. So my question is what should go where between SourceVersion & Webhooks so that the objective of ONLY triggering builds when either changes are pushed or a pull request is merged into my destination branch?


Solution

  • Dumb me! I was making a change to a file outside the webserver/ folder and with File Path filter it was obviously ignoring it as expected.