Reputation: 3296
The need - when merging a pull-request to a branch, I want CodeBuild to build the latest branch's commit, not the pull-request. I'm using CloudFormation, here's the triggers snippet:
Triggers:
Webhook: true
FilterGroups:
- - Type: EVENT
Pattern: PULL_REQUEST_CREATED, PULL_REQUEST_UPDATED, PULL_REQUEST_REOPENED
- Type: BASE_REF
Pattern: !Sub "refs/heads/${GithubBranchName}$"
ExcludeMatchedPattern: false
I've tried adding PULL_REQUEST_MERGED in the same CodeBuild project, but it builds the PR.
I've also tried creating a new CodeBuild project with PULL_REQUEST_MERGED only, and I tweaked the BASE_REF and HEAD_REF, but still no luck, the pull-request is built, instead of the branch.
Even though I'm using CloudFormation, feel free to reply with screenshots referring to AWS Console.
Is it even possible?
Upvotes: 3
Views: 2073
Reputation: 3296
I figured out the issue, I had to use the PUSH trigger instead of PULL_REQUEST_MERGED, and I also had corrupted webhooks in my GitHub repository.
So this is how I solved it - I've deleted all webhooks in GitHub, deleted the Codebuild project, added the PUSH trigger, here's the triggers snippet:
Triggers:
Webhook: true
FilterGroups:
- - Type: EVENT
Pattern: PULL_REQUEST_CREATED, PULL_REQUEST_UPDATED, PULL_REQUEST_REOPENED
- Type: BASE_REF
Pattern: !Sub "refs/heads/${GithubBranchName}$"
ExcludeMatchedPattern: false
- - Type: EVENT
Pattern: PUSH
- Type: HEAD_REF
Pattern: !Sub "refs/heads/${GithubBranchName}$"
ExcludeMatchedPattern: false
SourceVersion: !Sub ${GithubBranchName}
Recreated my CodeBuild project, so it recreated the relevant webhooks, now everything works as expected.
Upvotes: 5