From e8f5bd9a8b5fa4240e5ed4b16b5f5672f3bad9ee Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 8 Mar 2022 10:11:53 -0800 Subject: [PATCH 1/3] docs(pipelines): add examples for pipeline variables Fixes #19184. --- .../pipelines/lib/codepipeline/codebuild-step.ts | 14 ++++++++++++++ .../lib/codepipeline/codepipeline-source.ts | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts b/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts index c50d715e2cbe9..a7d620ac1e504 100644 --- a/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts +++ b/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts @@ -234,6 +234,20 @@ export class CodeBuildStep extends ShellStep { * it finishes its `post_build` phase. * * @param variableName the name of the variable for reference. + * @example + * // Access the output of one CodeBuildStep in another CodeBuildStep + * declare const pipeline: pipelines.CodePipeline; + * + * const step1 = new pipelines.CodeBuildStep('Step1', { + * commands: ['export MY_VAR=hello'], + * }); + * + * const step2 = new pipelines.CodeBuildStep('Step2', { + * env: { + * IMPORTED_VAR: step1.exportedVariable('MY_VAR'), + * } + * commands: ['echo $IMPORTED_VAR'], + * }); */ public exportedVariable(variableName: string): string { if (this.exportedVarsRendered && !this.exportedVariables.has(variableName)) { diff --git a/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline-source.ts b/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline-source.ts index 0f95d41f5c940..44778af3195e5 100644 --- a/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline-source.ts +++ b/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline-source.ts @@ -162,6 +162,19 @@ export abstract class CodePipelineSource extends Step implements ICodePipelineAc * - `RegistryId` * * @see https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-variables.html#reference-variables-list + * @example + * // Access the CommitId of a GitHub source in the synth + * const source = pipelines.CodePipelineSource.gitHub('owner/repo', 'main'); + * + * const pipeline = new pipelines.CodePipeline(scope, 'MyPipeline', { + * synth: new pipelines.ShellStep('Synth', { + * input: source, + * commands: [], + * env: { + * 'COMMIT_ID': source.sourceAttribute('CommitId'), + * } + * }) + * }); */ public sourceAttribute(name: string): string { return makeCodePipelineOutput(this, name); From 12e45f039bd6336a4f2deddda4f6ea00cb655da0 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 8 Mar 2022 14:01:42 -0800 Subject: [PATCH 2/3] Add comma --- .../@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts b/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts index a7d620ac1e504..1d95b98b550ed 100644 --- a/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts +++ b/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts @@ -233,6 +233,9 @@ export class CodeBuildStep extends ShellStep { * The variable must be set in the shell of the CodeBuild step when * it finishes its `post_build` phase. * + * ```ts + * ``` + * * @param variableName the name of the variable for reference. * @example * // Access the output of one CodeBuildStep in another CodeBuildStep @@ -245,7 +248,7 @@ export class CodeBuildStep extends ShellStep { * const step2 = new pipelines.CodeBuildStep('Step2', { * env: { * IMPORTED_VAR: step1.exportedVariable('MY_VAR'), - * } + * }, * commands: ['echo $IMPORTED_VAR'], * }); */ From 3b2b6ee8e00d4483af44a03e8ceb009a129626ed Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Wed, 9 Mar 2022 08:14:35 -0800 Subject: [PATCH 3/3] Update codebuild-step.ts --- packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts b/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts index 1d95b98b550ed..43519fdda97bf 100644 --- a/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts +++ b/packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts @@ -233,9 +233,6 @@ export class CodeBuildStep extends ShellStep { * The variable must be set in the shell of the CodeBuild step when * it finishes its `post_build` phase. * - * ```ts - * ``` - * * @param variableName the name of the variable for reference. * @example * // Access the output of one CodeBuildStep in another CodeBuildStep