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

(codepipeline-actions): custom event for codepipeline codecommit actions #12045

Closed
2 tasks
matwerber1 opened this issue Dec 13, 2020 · 8 comments · Fixed by #28008 · May be fixed by stack-spot/app-handler-functions-template#2, stack-spot/eks-env-ts-template#2 or stack-spot/web-react-deploy#4
Labels
@aws-cdk/aws-codepipeline-actions effort/large Large work item – several weeks of effort feature/service-integration Add functionality to an L2 construct to enable easier integration with another service feature-request A feature should be added or improved. p2

Comments

@matwerber1
Copy link
Contributor

This feature request is to allow customization of the CloudWatch Event created by a CodeCommit source action in the aws-codepipeline-actions module.

Use Case

Per the blog post below, one may want to add custom logic to the CloudWatch Event that triggers a pipeline, so that they can selectively determine when to trigger a pipeline rather than triggering it on every commit to the branch being watched. This customization may be done by having the CloudWatch Event invoke a Lambda rather than directly triggering the pipeline. The Lambda can apply logic to determine whether this (or a different) pipeline is triggered.

Today, the aws-codepipeline-actions CodeCommit source action does not allow you to specify / modify the rules of the CloudWatch Event created by the construct.

Inspiration for this request is from the blog below:

https://aws.amazon.com/blogs/devops/adding-custom-logic-to-aws-codepipeline-with-aws-lambda-and-amazon-cloudwatch-events/

I want to use trunk-based development (single master branch) but have the ability to selectively trigger a pipeline based on facts about the commit.

For example:

  1. If a README was the the only file changed, do not trigger the normal pipeline.

  2. If (e.g. in the event of an emergency), I need to push a hotfix straight to prod while skipping my test and staging environment, I want to invoke a different pipeline that is source -> build -> prod, instead of my normal pipeline of source-> test -> staging -> prod.

Proposed Solution

Proposed idea #1 is to able to specify your own, previously-created CloudWatch Event, e.g.:

new codepipeline_actions.CodeCommitSourceAction({
          actionName: 'CodeCommit_Source',
          role: props.role,
          eventRole: props.eventRole,
          repository: props.repository,
          branch: props.branch,
          output: props.output,
          event: <YOUR CUSTOM EVENT>        // FEATURE REQUEST
        }),

Idea 2 is to be able to customize the target parameters of the event created by the source action:

new codepipeline_actions.CodeCommitSourceAction({
          actionName: 'CodeCommit_Source',
          role: props.role,
          eventRole: props.eventRole,
          repository: props.repository,
          branch: props.branch,
          output: props.output,
          eventTarget:    <custom Lambda resource>.        // FEATURE REQUEST
}),

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@matwerber1 matwerber1 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 13, 2020
@SomayaB SomayaB changed the title aws-codepipeline-actions: custom event for codepipeline codecommit actions (codepipeline-actions): custom event for codepipeline codecommit actions Dec 14, 2020
@skinny85 skinny85 added effort/large Large work item – several weeks of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 14, 2020
@skinny85
Copy link
Contributor

Thanks for the feature request @matwerber1 . This is a big feature, and I'm not sure I completely agree with the use cases you've outlined (for example, If a README was the the only file changed, do not trigger the normal pipeline. - that seems very dangerous to me).

However, if you want to work on it, I'm happy to offer guidance in getting this in 🙂.

@matwerber1
Copy link
Contributor Author

I'm not 100% sure I agree with it either, but I have talked to some where it might make sense, and of course, the blog post suggests others may want to use the approach, too.

I can't promise I can find the time to work on it, but I'm not opposed to it. It would be fun to contribute to the CDK :) Is there a good starting point? My Typescript is not strong but may be a good learning opportunity.

@skinny85
Copy link
Contributor

The Contributing.md file is a good start. You can also check out my blog post on the subject (shameless plug): https://www.endoflineblog.com/cdk-tips-02-how-to-contribute-to-the-cdk

@kaiz-io
Copy link
Contributor

kaiz-io commented Dec 18, 2020

I just ran into this issue when trying to use a single source for hosting both CDK source and application source, while using CDK Pipelines for the continuous CDK deployment and AWS CodePipeline for Application deployment.

Everytime I update the CDK code it will fire both a build for CDK and app and vice versa. Unless this is a anti-pattern. I would imagine more people to have a issues as they adopt CDK Pipelines.

@ericzbeard ericzbeard added the feature/service-integration Add functionality to an L2 construct to enable easier integration with another service label Apr 2, 2021
@Rofor51
Copy link

Rofor51 commented Jul 27, 2021

This is still relevant. Would be great to have if you want to create a scheduled build after a commit.

@adamtimmins
Copy link

With CDK Pipelines this would be a hugely helpful feature.

@jolo-dev
Copy link
Contributor

@matwerber1 I think, I might have a solution for that:

Once you create the Pipeline, you can add (apparently not remove) events

const pipeline = new Pipeline(this, 'Pipeline');
const customLambdaTrigger = new Function(this, 'customLambdaTrigger', {
      /* your configs */
      initialPolicy: [
        new PolicyStatement({
          actions: ['codecommit:GetDifferences'],
          resources: [repository.repositoryArn],
        }),
        new PolicyStatement({
          actions: ['codepipeline:StartPipelineExecution'],
          resources: [pipeline.pipelineArn],
        }),
      ],
    });
const eventPattern
      = {
        'detail-type': ['CodeCommit Repository State Change'],
        'resources': [repository.repositoryArn],
        'source': ['aws.codecommit'],
        'detail': {
          referenceType: ['branch'],
          event: ['referenceCreated', 'referenceUpdated'],
          referenceName: ['main'],
        },
      };
pipeline.onEvent('EventTrigger', {
      eventPattern,
      description: 'Trigger the pipeline when a commit is pushed to the master branch',
      target: new LambdaFunction(customLambdaTrigger),
 });

You need to disable the default rules of CodeCommitSourceAction (manually).

CC: @skinny85

mergify bot pushed a commit that referenced this issue Jan 16, 2024
…t source action (#28008)

Custom Events were added to the CodeCommit Source action to trigger pipelines via custom event rules.

Closes [#12045](#12045).

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@mergify mergify bot closed this as completed in #28008 Jan 16, 2024
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment