【发布时间】:2022-01-20 12:46:19
【问题描述】:
我们正在尝试从 v1 CdkPipeline 迁移到 v2 CodePipelin。在 v1 中有这个 manualApproval 属性,必须将其设置为 true,然后您在创建变更集后获得手动批准。这似乎不再存在,所以我尝试关注new way,但由于某些未知原因,我在尝试创建 cdk diff 时收到此错误:
Deployment step 'ManualApprovalStep(ChangeSet Approval)' is not supported for CodePipeline-backed pipelines
这是实际代码:
const jfrogSsm = StringParameter.fromSecureStringParameterAttributes(this, 'ssm', {
parameterName: '/some-key',
version: 1,
});
const additionalPermissions = new PolicyStatement();
additionalPermissions.addActions('ssm:GetParameters');
additionalPermissions.addResources(ssm.parameterArn);
const pipeline = new OrgCodePipeline(this, 'Pipeline', {
pipelineName: 'pipeline',
stage: 'prd',
github: {
repo: 'repo-name',
branch: 'master',
},
synthAction: {
subdirectory: 'infrastructure',
jfrogApiKey: {
type: BuildEnvironmentVariableType.PARAMETER_STORE,
value: jfrogSsm.parameterName,
},
buildCommand: 'npx run build',
rolePolicyStatements: [additionalPermissions],
},
});
pipeline.addStage(new MyStage(this, 'MyInfra'), {
pre: [new ManualApprovalStep('ManualApproval')],
});
pipeline.attachSlackHook({
emoji: ':frog:',
mention: '@team-name',
});
attachSlackHook:创建一个通知 Lambda,它将消息发送到 slack,并连接到 cdks 管道内 aws-codepipeline 的 onStateChange 方法。为了在 v2 中实现这一点,我们需要将其作为最后的附加调用,因为我们需要首先调用 buildPipeline 来访问内部的内部 aws-codepipeline。
我们有一个内部构造库,它设置了一些默认值(这里称为 OrgCodePipeline),构造如下:
export class OrgCodePipeline extends Construct {
public readonly pipelineName: string;
public readonly pipeline: CodePipeline;
private readonly stage: string;
public constructor(scope: Construct, id: string, props: OrgCodePipelineProps) {
super(scope, id);
this.pipelineName = props.pipelineName;
this.stage = props.stage;
const commands = createCommands(
props.stage,
props.synthAction.subdirectory,
props.synthAction.synthCommand,
props.synthAction.buildCommand,
);
const input = this.createCodeStarConnection(props.github);
const synth = new CodeBuildStep('Synth', {
installCommands: createInstallCommand(props.synthAction.synthType),
commands,
input,
env: {
JFROG_API_KEY: props.synthAction.jfrogApiKey.value,
},
rolePolicyStatements: props.synthAction.rolePolicyStatements,
primaryOutputDirectory: 'cdk.out',
buildEnvironment: {
buildImage: LinuxBuildImage.STANDARD_5_0,
},
});
this.pipeline = new CodePipeline(this, id, {
pipelineName: props.pipelineName,
crossAccountKeys: false,
synth,
});
}
createCommands:获取所有命令并将它们连接起来。在 v1 中,它们被分为合成命令和构建命令。
createCodeStarConnection:为我们的 github 组织内的给定 repo 和分支创建一个 CfnConnection,并返回 CodePipelineSource。
createInstallCommand:为 npm 或 yarn 创建安装命令。还要确保使用我们的私有 jfrog 工件
提前感谢您的帮助!
【问题讨论】:
-
OrgCodePipeline是什么?它的addStage有什么作用? -
您确定您使用的是正确的 ManualApprovalStep 吗?代码表明它应该可以工作——github.com/aws/aws-cdk/blob/…
-
@kichik 他们在自己的自定义类上调用
addStage,而不是pipelines.CodePipeline,所以谁知道他们的实现是什么。 -
它只是将调用转发给真正的 CodePipelines addStage 函数,因此您不需要调用 pipeline.pipeline.addStage()。这是实现:``` public addStage(stage: Stage, options?: AddStageOpts): StageDeployment { return this.pipeline.addStage(stage, options); } ``` 两种方式都会出现同样的错误
标签: amazon-web-services aws-cdk aws-codepipeline