gpt4 book ai didi

amazon-web-services - 如何将 AWS 管道指定为 CDK 中代码构建项目的源提供者?

转载 作者:行者123 更新时间:2023-12-05 04:53:59 25 4
gpt4 key购买 nike

当我在 AWS 控制台中创建代码构建项目时,我可以选择 AWS CodePipeline 作为源提供程序。请参见下面的屏幕截图。

enter image description here

但是在 CDK 中,https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-codebuild.Source.html ,我找不到如何将 AWS CodePipeline 指定为源提供程序。如何在 CDK 中实现?

最佳答案

似乎您将代码构建操作分配给代码管道,而不是将代码管道添加到代码构建项目源。

https://docs.aws.amazon.com/cdk/api/latest/docs/aws-codebuild-readme.html#codepipeline

To add a CodeBuild Project as an Action to CodePipeline, use the PipelineProject class instead of Project. It's a simple class that doesn't allow you to specify sources, secondarySources, artifacts or secondaryArtifacts, as these are handled by setting input and output CodePipeline Artifact instances on the Action, instead of setting them on the Project.

https://docs.aws.amazon.com/cdk/api/latest/docs/aws-codepipeline-actions-readme.html#build--test

Example of a CodeBuild Project used in a Pipeline, alongside CodeCommit:

import * as codebuild from '@aws-cdk/aws-codebuild';
import * as codecommit from '@aws-cdk/aws-codecommit';
import * as codepipeline_actions from '@aws-cdk/aws-codepipeline-actions';

const repository = new codecommit.Repository(this, 'MyRepository', {
repositoryName: 'MyRepository',
});
const project = new codebuild.PipelineProject(this, 'MyProject');

const sourceOutput = new codepipeline.Artifact();
const sourceAction = new codepipeline_actions.CodeCommitSourceAction({
actionName: 'CodeCommit',
repository,
output: sourceOutput,
});
const buildAction = new codepipeline_actions.CodeBuildAction({
actionName: 'CodeBuild',
project,
input: sourceOutput,
outputs: [new codepipeline.Artifact()], // optional
executeBatchBuild: true // optional, defaults to false
});

new codepipeline.Pipeline(this, 'MyPipeline', {
stages: [
{
stageName: 'Source',
actions: [sourceAction],
},
{
stageName: 'Build',
actions: [buildAction],
},
],
});

关于amazon-web-services - 如何将 AWS 管道指定为 CDK 中代码构建项目的源提供者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65900239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com