Skip to content

Commit

Permalink
Trigger pipeline on latest tag if require_image_build is not selected
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnStainsby committed Jan 17, 2025
1 parent 22753cd commit a886ed1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion codebase-pipelines/eventbridge.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resource "aws_cloudwatch_event_rule" "ecr_image_publish" {
detail-type : ["ECR Image Action"],
detail : {
action-type : ["PUSH"],
image-tag : [coalesce(each.value.tag, false) ? "tag-latest" : "branch-${each.value.branch}"],
image-tag : [var.requires_image_build ? coalesce(each.value.tag, false) ? "tag-latest" : "branch-${each.value.branch}" : "latest"],
repository-name : [local.ecr_name],
result : ["SUCCESS"],
}
Expand Down
8 changes: 8 additions & 0 deletions codebase-pipelines/tests/unit.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ run "test_codebuild_images_not_required" {
condition = length(aws_codebuild_webhook.codebuild_webhook) == 0
error_message = "Should be: 0"
}
assert {
condition = aws_cloudwatch_event_rule.ecr_image_publish[0].event_pattern == "{\"detail\":{\"action-type\":[\"PUSH\"],\"image-tag\":[\"latest\"],\"repository-name\":[\"my-app/my-codebase\"],\"result\":[\"SUCCESS\"]},\"detail-type\":[\"ECR Image Action\"],\"source\":[\"aws.ecr\"]}"
error_message = "Event pattern is incorrect ${jsonencode(aws_cloudwatch_event_rule.ecr_image_publish[0].event_pattern)}"
}
assert {
condition = aws_cloudwatch_event_rule.ecr_image_publish[1].event_pattern == "{\"detail\":{\"action-type\":[\"PUSH\"],\"image-tag\":[\"latest\"],\"repository-name\":[\"my-app/my-codebase\"],\"result\":[\"SUCCESS\"]},\"detail-type\":[\"ECR Image Action\"],\"source\":[\"aws.ecr\"]}"
error_message = "Event pattern is incorrect"
}
}

run "test_main_branch_filter" {
Expand Down

0 comments on commit a886ed1

Please sign in to comment.