Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(codebuild): add startBatchBuild option #11743

Merged
merged 14 commits into from
Dec 24, 2020

Conversation

tjenkinson
Copy link
Contributor

@tjenkinson tjenkinson commented Nov 26, 2020

This adds a startBatchBuild option to the code build source, to trigger a batch build. The cloudformation property isn't in the official docs yet but is mentioned here.

Closes #11663

@gitpod-io
Copy link

gitpod-io bot commented Nov 26, 2020

@github-actions github-actions bot added the @aws-cdk/aws-codebuild Related to AWS CodeBuild label Nov 26, 2020
@tjenkinson
Copy link
Contributor Author

tjenkinson commented Nov 27, 2020

@skinny85 do you know why BuildType is not appearing in the template? There are no type errors and buildType on buildTriggers also exists in the (generated) types.

I guess somewhere else needs updating?

Edit: nevermind, Just spotted the problem :|

@tjenkinson tjenkinson marked this pull request as ready for review November 27, 2020 22:32
@skinny85 skinny85 changed the title feat(aws-codebuild): add startBatchBuild option feat(codebuild): add startBatchBuild option Nov 30, 2020
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome contribution @tjenkinson ! Just a few questions/comments before I "ShipIt".

packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-codebuild/README.md Outdated Show resolved Hide resolved
@@ -482,6 +482,13 @@ interface ThirdPartyGitSourceProps extends GitSourceProps {
*/
readonly webhook?: boolean;

/**
* Start a batch build when the webhook is triggered instead of a standard one.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "when the webhook is triggered" is an interesting statement. So this setting works only for builds started through the webhook? Not through, for instance, CloudWatch Events?

If that is indeed the case, I'd like to change this a little bit:

  1. Let's call this property webhookTriggersBatchBuild?: boolean instead, to make it absolutely clear what it does.
  2. If webhookTriggersBatchBuild is passed as true, but webhook is false (which gets a little complicated because webhook is considered true if it's undefined, but webhookFilters have been provided), that sounds like an error to me, and we should validate that scenario (and check that logic with a separate unit test, of course 🙂).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm good question. I assume it applies for anything that triggers. Asked here: aws-cloudformation/cloudformation-coverage-roadmap#621 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjenkinson can you perhaps do an experiment with that setting and CloudWatch Events, and report back what you find? I don't want to hold your PR hostage to this question 🙂.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the console
image

It really implies it's just webhooks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the docs here I don't think it's possible to trigger a batch build from cloudwatch, because it mentions that any options you provide are for the StartBuild call, not StartBuildBatch

For more information about the parameters you can pass, see StartBuild. You cannot pass the projectName parameter in this field. Instead, you specify the project using the ARN in Project ARN.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjenkinson OK. Let's assume that it is the case then, and let's implement the 2 points I made here #11743 (comment) .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skinny85 currently if you pass webhooks: false and also provide filter groups, then the end result is no error, and the SourceConfig contains webhook false and the filter groups.

So I followed the same logic and decided to default webhooks to true if it was omitted and there were filter groups or webhookTriggersBatchBuild was true.

Also if you explicitly set webhooks to false we will leave it as false but still set the buildType in the SourceConfig just like we do with the filters.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like passing webhooks: false, but webhookFilters is probably a mistake...

In fact, I just tried it, and I got the following error from CodeBuild's API:

Failed to call CreateWebhook, reason: Cannot specify filter groups when webhook is disabled.
(Service: null; Status Code: 400; Error Code: null; Request ID: null; Proxy: null)

This makes me believe that adding this validation for webhookTriggersBatchBuild is the correct thing to do (I won't bother you with adding it for webhookFilters, as it's not really the topic of this PR).

@mergify mergify bot dismissed skinny85’s stale review November 30, 2020 20:54

Pull request has been modified.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting in "Request changes" to remove it from y ToDo-list. @tjenkinson when you've updated the PR, please make sure to re-request my review!

@mergify mergify bot dismissed skinny85’s stale review December 21, 2020 12:52

Pull request has been modified.

@tjenkinson
Copy link
Contributor Author

Oh build failed. Will look into that. It worked locally

@tjenkinson tjenkinson marked this pull request as draft December 21, 2020 13:52
@tjenkinson tjenkinson marked this pull request as ready for review December 21, 2020 16:14
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic contribution @tjenkinson ! Fix the behavior for webhookTriggersBatchBuild being true, but webhook being given as false (it should throw an exception), and I'll gladly merge this one in 🙂.

Thanks,
Adam

packages/@aws-cdk/aws-codebuild/lib/source.ts Outdated Show resolved Hide resolved
@mergify mergify bot dismissed skinny85’s stale review December 24, 2020 10:30

Pull request has been modified.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @tjenkinson !

@mergify
Copy link
Contributor

mergify bot commented Dec 24, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 34d7203
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Dec 24, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit d9353b7 into aws:master Dec 24, 2020
flochaz pushed a commit to flochaz/aws-cdk that referenced this pull request Jan 5, 2021
This adds a `startBatchBuild` option to the code build source, to trigger a batch build. The cloudformation property isn't in the official docs yet but is mentioned [here](aws-cloudformation/cloudformation-coverage-roadmap#621 (comment)).

Closes aws#11663
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[aws-codebuild] support webhook ''BUILD_BATCH" BuildType
3 participants