Skip to content

Commit a6d52aa

Browse files
authored
docs(pipelines): add examples for pipeline variables (#19288)
Fixes #19184. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent efa20ee commit a6d52aa

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,20 @@ export class CodeBuildStep extends ShellStep {
234234
* it finishes its `post_build` phase.
235235
*
236236
* @param variableName the name of the variable for reference.
237+
* @example
238+
* // Access the output of one CodeBuildStep in another CodeBuildStep
239+
* declare const pipeline: pipelines.CodePipeline;
240+
*
241+
* const step1 = new pipelines.CodeBuildStep('Step1', {
242+
* commands: ['export MY_VAR=hello'],
243+
* });
244+
*
245+
* const step2 = new pipelines.CodeBuildStep('Step2', {
246+
* env: {
247+
* IMPORTED_VAR: step1.exportedVariable('MY_VAR'),
248+
* },
249+
* commands: ['echo $IMPORTED_VAR'],
250+
* });
237251
*/
238252
public exportedVariable(variableName: string): string {
239253
if (this.exportedVarsRendered && !this.exportedVariables.has(variableName)) {

packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline-source.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@ export abstract class CodePipelineSource extends Step implements ICodePipelineAc
162162
* - `RegistryId`
163163
*
164164
* @see https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-variables.html#reference-variables-list
165+
* @example
166+
* // Access the CommitId of a GitHub source in the synth
167+
* const source = pipelines.CodePipelineSource.gitHub('owner/repo', 'main');
168+
*
169+
* const pipeline = new pipelines.CodePipeline(scope, 'MyPipeline', {
170+
* synth: new pipelines.ShellStep('Synth', {
171+
* input: source,
172+
* commands: [],
173+
* env: {
174+
* 'COMMIT_ID': source.sourceAttribute('CommitId'),
175+
* }
176+
* })
177+
* });
165178
*/
166179
public sourceAttribute(name: string): string {
167180
return makeCodePipelineOutput(this, name);

0 commit comments

Comments
 (0)