OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Gitlab Webhook to AWS Codebuild behaving weirdly

  • Thread starter Thread starter Bruno Bertolini Rabello
  • Start date Start date
B

Bruno Bertolini Rabello

Guest
I recently found out that AWS CodeBuild now has a native integration with GitLab and GitLab Self-Managed, so I tried to move our CI/CD to AWS. Initial tests were fine; things were working, but suddenly the webhooks stopped triggering. There were no signs of them in CloudTrail and no indications of anything wrong; all responses were 200s in the GitLab webhook settings. I thought the filters might be causing the issue, so I removed all of them to ensure any code change would trigger a build. Still, nothing happened. The next day, I got to work and saw that 50 different triggers had fired that morning from other people's code changes, and everything was working again. I rebuilt the filters, and the job was getting done. However, the day after, nothing worked again.

This is my Terraform Setup for Codebuild:

Code:
resource "aws_codebuild_project" "codebuild_project" {
    name                            = "${local.api_name}"
    description                     = "${local.api_name}-project"
    service_role                    = role.arn

    source {
        type                        = "GITLAB_SELF_MANAGED"
        location                    = data.gitlab_project.git_project.web_url
        report_build_status         = true
        buildspec                   = buildspec.yml
    }

    environment {
        compute_type                = "BUILD_GENERAL1_SMALL"
        image                       = "aws/codebuild/amazonlinux2-x86_64-standard:5.0"
        type                        = "LINUX_CONTAINER"
        privileged_mode             = true
  }

    artifacts {
        type                        = "NO_ARTIFACTS"
    }

    vpc_config {
      vpc_id                        = vpc.id
      subnets                       = subnet.id
      security_group_ids            = sg.id
    }
}

resource "aws_codebuild_webhook" "codebuild_webhook" {
    project_name = "${local.api_name}"
    filter_group {
        filter {
            type = "EVENT"
            pattern = "PULL_REQUEST_MERGED"
            exclude_matched_pattern = false
        }
        filter {
            type = "BASE_REF"
            pattern = <<PATTERN_BASE_REF
.*release.*
PATTERN_BASE_REF
            exclude_matched_pattern = false
        }
    }
    build_type = "BUILD"
}

I tried removing the buildspec VPC, putting it back again, changing connections and hosts in AWS CodeStar Connections, triggering push-only and merge-requests-only builds, deleting the Terraform resources and recreating them, but nothing worked. I have messed with filters, used no filter, checked my GitLab to ensure the webhook was being created correctly (it was), checked permissions for everything (even set everything to admin just to see), created and destroyed the resources multiple times, and read the documentation on the subject, but nothing seems to work definitively.
<p>I recently found out that AWS CodeBuild now has a native integration with GitLab and GitLab Self-Managed, so I tried to move our CI/CD to AWS. Initial tests were fine; things were working, but suddenly the webhooks stopped triggering. There were no signs of them in CloudTrail and no indications of anything wrong; all responses were 200s in the GitLab webhook settings. I thought the filters might be causing the issue, so I removed all of them to ensure any code change would trigger a build. Still, nothing happened. The next day, I got to work and saw that 50 different triggers had fired that morning from other people's code changes, and everything was working again. I rebuilt the filters, and the job was getting done. However, the day after, nothing worked again.</p>
<p>This is my Terraform Setup for Codebuild:</p>
<pre><code>resource "aws_codebuild_project" "codebuild_project" {
name = "${local.api_name}"
description = "${local.api_name}-project"
service_role = role.arn

source {
type = "GITLAB_SELF_MANAGED"
location = data.gitlab_project.git_project.web_url
report_build_status = true
buildspec = buildspec.yml
}

environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "aws/codebuild/amazonlinux2-x86_64-standard:5.0"
type = "LINUX_CONTAINER"
privileged_mode = true
}

artifacts {
type = "NO_ARTIFACTS"
}

vpc_config {
vpc_id = vpc.id
subnets = subnet.id
security_group_ids = sg.id
}
}

resource "aws_codebuild_webhook" "codebuild_webhook" {
project_name = "${local.api_name}"
filter_group {
filter {
type = "EVENT"
pattern = "PULL_REQUEST_MERGED"
exclude_matched_pattern = false
}
filter {
type = "BASE_REF"
pattern = <<PATTERN_BASE_REF
.*release.*
PATTERN_BASE_REF
exclude_matched_pattern = false
}
}
build_type = "BUILD"
}
</code></pre>
<p>I tried removing the buildspec VPC, putting it back again, changing connections and hosts in AWS CodeStar Connections, triggering push-only and merge-requests-only builds, deleting the Terraform resources and recreating them, but nothing worked. I have messed with filters, used no filter, checked my GitLab to ensure the webhook was being created correctly (it was), checked permissions for everything (even set everything to admin just to see), created and destroyed the resources multiple times, and read the documentation on the subject, but nothing seems to work definitively.</p>
Continue reading...
 

Latest posts

Top