Skip to content

Commit

Permalink
docs(pipelines): add examples for pipeline variables (aws#19288)
Browse files Browse the repository at this point in the history
Fixes aws#19184.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored and TheRealAmazonKendra committed Mar 11, 2022
1 parent 81eda47 commit 93553a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 93553a9

Please sign in to comment.