简体   繁体   English

如何指定目录来触发代码管道cdk?

[英]How to Specify directory to trigger code pipeline cdk?

I am using a cdk code pipeline and i would like to specify for it to only trigger if a directory within the repo has changed.我正在使用 cdk 代码管道,我想指定它仅在 repo 中的目录发生更改时触发。

const pipeline = new CodePipeline(this, 'Pipeline', {
    pipelineName: 'BackEndPipeline',
    synth: new CodeBuildStep('SynthStep', {
        input: CodePipelineSource.codeCommit(repo, 'master'),
        installCommands: [
            'npm install -g aws-cdk'
        ],
        commands: [
            'cd mydir',
            'ls',
            'npm install',
            'ls',
            'npm run build',
            'ls',
            'npx cdk synth'
        ],
        primaryOutputDirectory: 'mydir/cdk.out'
    })
});

It's a DIY job.这是一项 DIY 工作。 A CodePipeline is designed to run from start to finish, unconditionally. CodePipeline 旨在无条件地从头到尾运行。 The trick is to trigger the pipeline only when there has been a relevant change.诀窍是仅在发生相关更改时才触发管道。 You must replace the default trigger-on-every-change setup with manual triggering logic.您必须用手动触发逻辑替换默认的每次更改时触发设置。 For a CodeCommit repo:对于CodeCommit库:

(1) Turn off the pipeline's automatic trigger. (1) 关闭流水线的自动触发。 Set the trigger: codepipeline_actions.CodeCommitTrigger.NONE prop in the CodePipelineSource .CodePipelineSource中设置trigger: codepipeline_actions.CodeCommitTrigger.NONE道具。

(2) Create an EventBridge Rule to listen to your repo's commit events: (2) 创建一个EventBridge 规则来监听你的 repo 的提交事件:

const rule = new events.Rule(this, 'MyRule', {
  eventPattern: {
    source: ['aws.codecommit'],
    resources: ['arn:aws:codecommit:us-east-1:123456789012:my-repo'],
    detailType: ['CodeCommit Repository State Change'],
  },
});

(3) Add a Lambda as the rule's target . (3) 添加一个 Lambda 作为规则的目标 The Lambda will receive the referenceUpdated payload on a push to your repo. Lambda 将在推送到您的存储库时收到referenceUpdated 有效负载 The event payload contains the commitId , but not the changed files.事件负载包含commitId ,但不包含更改的文件。 To get the file-level changes, your Lambda should call the GetDifferences API. Your Lambda should then determine whether a relevant change has taken place.要获得文件级更改,您的 Lambda 应调用GetDifferences API。然后您的 Lambda 应确定是否发生了相关更改。

(4) Manually trigger a pipeline excecution if required. (4) 如果需要,手动触发流水线执行。 Your Lambda should call the StartPipelineExecution API or set the pipeline as a custom Event target .您的 Lambda 应该调用StartPipelineExecution API 或将管道设置为自定义事件目标

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建代码管道阶段以在 github 中部署带有源代码的 React 应用程序? [CDK 2.0] - How to create a code pipeline stage to deploy React application with source code in github? [CDK 2.0] AWS CDK 代码管道开发——NodejsFunction Package.json 依赖项如何安装? - AWS CDK Code Pipeline Development - How Do I Install NodejsFunction Package.json Dependencies? cdk FargateService中如何指定VPC ID - How to specify VPC ID in cdk FargateService AWS CDK 代码管道开发 - Typescript 错误 TS2307 - AWS CDK Code Pipeline Development - Typescript Error TS2307 AWS CDK 代码管道开发 - 错误 TS1005:预期为“]” - AWS CDK Code Pipeline Development - error TS1005: ']' expected Cloud Assembly Schema 版本不匹配——在 CDK 中构建代码管道 - Cloud Assembly Schema Version Mismatch - Building A Code Pipeline In The CDK 使用 CodeBuildStep 的代码管道的 AWS CDK 合成器错误 - AWS CDK synth errors out for a Code Pipeline with CodeBuildStep 我们可以使用 GitLab 作为 AWS CDK 管道源代码的主机吗? - Can we use GitLab as host for source code with AWS CDK pipeline? AWS CDK:如何在没有代码的情况下创建 lambda - AWS CDK: How to create lambda without code 通过 AWS 上的 CDK 管道构建代码时,我可以在 Github 上标记我的代码吗? - Can I tag my code on Github when building it through a CDK Pipeline on AWS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM