From 31a347a419abfab06f05dfc2c1be958813c9da18 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Fri, 31 May 2019 17:56:33 -0700 Subject: [PATCH] feat(codepipeline): final form of the CodeBuild Pipeline action. BREAKING CHANGE: the output and extraOutputs properties of the CodeBuildAction were merged into one property, outputs. --- packages/@aws-cdk/app-delivery/README.md | 2 +- .../test/test.pipeline-deploy-stack-action.ts | 2 +- .../aws-codepipeline-actions/README.md | 8 +++--- .../lib/codebuild/build-action.ts | 26 +++++++------------ .../test.cloudformation-pipeline-actions.ts | 2 +- ...ambda-deployed-through-codepipeline.lit.ts | 4 +-- ...line-code-build-multiple-inputs-outputs.ts | 6 ++--- .../test/integ.pipeline-code-commit-build.ts | 2 +- .../test/integ.pipeline-ecs-deploy.ts | 2 +- .../test/integ.pipeline-events.ts | 2 +- .../test/test.pipeline.ts | 2 +- packages/decdk/examples/pipeline.json | 10 ++++--- 12 files changed, 31 insertions(+), 37 deletions(-) diff --git a/packages/@aws-cdk/app-delivery/README.md b/packages/@aws-cdk/app-delivery/README.md index 740ec8ead94c0..d07a38ac601b4 100644 --- a/packages/@aws-cdk/app-delivery/README.md +++ b/packages/@aws-cdk/app-delivery/README.md @@ -89,7 +89,7 @@ const buildAction = new codepipeline_actions.CodeBuildAction({ actionName: 'CodeBuild', project, input: sourceOutput, - output: synthesizedApp, + outputs: [synthesizedApp], }); pipeline.addStage({ name: 'build', diff --git a/packages/@aws-cdk/app-delivery/test/test.pipeline-deploy-stack-action.ts b/packages/@aws-cdk/app-delivery/test/test.pipeline-deploy-stack-action.ts index 95feb1fec7e51..ad7713ed81d80 100644 --- a/packages/@aws-cdk/app-delivery/test/test.pipeline-deploy-stack-action.ts +++ b/packages/@aws-cdk/app-delivery/test/test.pipeline-deploy-stack-action.ts @@ -348,7 +348,7 @@ function createSelfUpdatingStack(pipelineStack: cdk.Stack): SelfUpdatingPipeline actionName: 'CodeBuild', project, input: sourceOutput, - output: buildOutput, + outputs: [buildOutput], }); pipeline.addStage({ name: 'build', diff --git a/packages/@aws-cdk/aws-codepipeline-actions/README.md b/packages/@aws-cdk/aws-codepipeline-actions/README.md index c671db8b4bfa3..7876f73bbf8bf 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/README.md +++ b/packages/@aws-cdk/aws-codepipeline-actions/README.md @@ -166,7 +166,7 @@ const buildAction = new codepipeline_actions.CodeBuildAction({ actionName: 'CodeBuild', project, input: sourceOutput, - output: new codepipeline.Artifact(), // optional + outputs: [new codepipeline.Artifact()], // optional }); new codepipeline.Pipeline(this, 'MyPipeline', { @@ -233,11 +233,11 @@ const buildAction = new codepipeline_actions.CodeBuildAction({ actionName: 'Build', project, input: sourceOutput1, - output: new codepipeline.Artifact('artifact1'), // for better buildspec readability - see below extraInputs: [ sourceOutput2, // this is where 'source2' comes from ], - extraOutputs: [ + outputs: [ + new codepipeline.Artifact('artifact1'), // for better buildspec readability - see below new codepipeline.Artifact('artifact2'), ], }); @@ -246,7 +246,7 @@ const buildAction = new codepipeline_actions.CodeBuildAction({ **Note**: when a CodeBuild Action in a Pipeline has more than one output, it only uses the `secondary-artifacts` field of the buildspec, never the primary output specification directly under `artifacts`. Because of that, it -pays to name even your primary output artifact on the Pipeline, like we did +pays to explicitly name all output artifacts of that Action, like we did above, so that you know what name to use in the buildspec. Example buildspec for the above project: diff --git a/packages/@aws-cdk/aws-codepipeline-actions/lib/codebuild/build-action.ts b/packages/@aws-cdk/aws-codepipeline-actions/lib/codebuild/build-action.ts index 12950f0f64d18..2826f438c67db 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/lib/codebuild/build-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/lib/codebuild/build-action.ts @@ -36,14 +36,16 @@ export interface CodeBuildActionProps extends codepipeline.CommonActionProps { readonly extraInputs?: codepipeline.Artifact[]; /** - * The optional primary output Artifact of this action. - */ - readonly output?: codepipeline.Artifact; - - /** - * The list of additional output Artifacts for this action. + * The list of output Artifacts for this action. + * **Note**: if you specify more than one output Artifact here, + * you cannot use the primary 'artifacts' section of the buildspec; + * you have to use the 'secondary-artifacts' section instead. + * See https://docs.aws.amazon.com/codebuild/latest/userguide/sample-multi-in-out.html + * for details. + * + * @default the action will not have any outputs */ - readonly extraOutputs?: codepipeline.Artifact[]; + readonly outputs?: codepipeline.Artifact[]; /** * The action's Project. @@ -74,7 +76,6 @@ export class CodeBuildAction extends codepipeline.Action { provider: 'CodeBuild', artifactBounds: { minInputs: 1, maxInputs: 5, minOutputs: 0, maxOutputs: 5 }, inputs: [props.input, ...props.extraInputs || []], - outputs: getOutputs(props), resource: props.project, configuration: { ProjectName: props.project.projectName, @@ -107,12 +108,3 @@ export class CodeBuildAction extends codepipeline.Action { } } } - -function getOutputs(props: CodeBuildActionProps): codepipeline.Artifact[] { - const ret = new Array(); - if (props.output) { - ret.push(props.output); - } - ret.push(...props.extraOutputs || []); - return ret; -} diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts index bfdecd46ea297..da6b2d30cc797 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/cloudformation/test.cloudformation-pipeline-actions.ts @@ -48,7 +48,7 @@ export = { actionName: 'build', project, input: sourceOutput, - output: buildOutput, + outputs: [buildOutput], }); pipeline.addStage({ name: 'build', diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts index 752bad003e2c1..4b67b20d5a153 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts @@ -70,7 +70,7 @@ const cdkBuildAction = new codepipeline_actions.CodeBuildAction({ actionName: 'CDK_Build', project: cdkBuildProject, input: cdkSourceOutput, - output: cdkBuildOutput, + outputs: [cdkBuildOutput], }); // build your Lambda code, using CodeBuild @@ -103,7 +103,7 @@ const lambdaBuildAction = new codepipeline_actions.CodeBuildAction({ actionName: 'Lambda_Build', project: lambdaBuildProject, input: lambdaSourceOutput, - output: lambdaBuildOutput, + outputs: [lambdaBuildOutput], }); pipeline.addStage({ diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-build-multiple-inputs-outputs.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-build-multiple-inputs-outputs.ts index 697c2a118832a..e41e602496952 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-build-multiple-inputs-outputs.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-build-multiple-inputs-outputs.ts @@ -50,8 +50,8 @@ const buildAction = new cpactions.CodeBuildAction({ extraInputs: [ source2Output, ], - output: new codepipeline.Artifact(), - extraOutputs: [ + outputs: [ + new codepipeline.Artifact(), new codepipeline.Artifact(), ], }); @@ -63,7 +63,7 @@ const testAction = new cpactions.CodeBuildAction({ extraInputs: [ source1Output, ], - extraOutputs: [ + outputs: [ new codepipeline.Artifact('CustomOutput2'), ], }); diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts index 684adf25b73f1..b8020e81ca084 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-code-commit-build.ts @@ -26,7 +26,7 @@ const buildAction = new cpactions.CodeBuildAction({ actionName: 'build', project, input: sourceOutput, - output: new codepipeline.Artifact(), + outputs: [new codepipeline.Artifact()], }); const testAction = new cpactions.CodeBuildAction({ type: cpactions.CodeBuildActionType.TEST, diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-ecs-deploy.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-ecs-deploy.ts index 0c28e37681bb4..063daf62b504f 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-ecs-deploy.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-ecs-deploy.ts @@ -80,7 +80,7 @@ const buildAction = new cpactions.CodeBuildAction({ actionName: 'CodeBuild', project, input: sourceOutput, - output: buildOutput, + outputs: [buildOutput], }); new codepipeline.Pipeline(stack, 'MyPipeline', { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-events.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-events.ts index 2b4ad4118d0f5..82390aeab3b3a 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-events.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-events.ts @@ -39,7 +39,7 @@ pipeline.addStage({ actionName: 'CodeBuildAction', input: sourceOutput, project, - output: new codepipeline.Artifact(), + outputs: [new codepipeline.Artifact()], }), ], }); diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts index d66abf0b94a25..8a26b9d0c109e 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts @@ -751,7 +751,7 @@ export = { actionName: 'CodeBuild', project, input: sourceOutput, - output: new codepipeline.Artifact(), + outputs: [new codepipeline.Artifact()], }), ], }, diff --git a/packages/decdk/examples/pipeline.json b/packages/decdk/examples/pipeline.json index a616e4a11d450..f87133e7d6b47 100644 --- a/packages/decdk/examples/pipeline.json +++ b/packages/decdk/examples/pipeline.json @@ -48,11 +48,13 @@ "name": "Source" } }, - "output": { - "artifact": { - "name": "Build" + "outputs": [ + { + "artifact": { + "name": "Build" + } } - } + ] } } ]