Skip to content

Commit

Permalink
Update ReadMe files.
Browse files Browse the repository at this point in the history
  • Loading branch information
skinny85 committed Jan 2, 2020
1 parent 849701a commit 88ca213
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 9 deletions.
176 changes: 174 additions & 2 deletions packages/@aws-cdk/aws-codepipeline-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ pipeline.addStage({
});
```

The CodeCommit source action produces variables:

```typescript
const codeCommitSourceVariables = new codepipeline_actions.CodeCommitSourceVariables();
const sourceAction = new codepipeline_actions.CodeCommitSourceAction({
// ...
variables: codeCommitSourceVariables,
});

// later:

new codepipeline_actions.CodeBuildAction({
// ...
environmentVariables: {
COMMIT_ID: {
value: codeCommitSourceVariables.commitId,
},
},
});
```

#### GitHub

To use GitHub as the source of a CodePipeline:
Expand All @@ -66,6 +87,27 @@ pipeline.addStage({
});
```

The GitHub source action produces variables:

```typescript
const gitHubSourceVariables = new codepipeline_actions.GitHubSourceVariables();
const sourceAction = new codepipeline_actions.GitHubSourceAction({
// ...
variables: gitHubSourceVariables,
});

// later:

new codepipeline_actions.CodeBuildAction({
// ...
environmentVariables: {
COMMIT_ID: {
value: gitHubSourceVariables.commitId,
},
},
});
```

#### AWS S3

To use an S3 Bucket as a source in CodePipeline:
Expand Down Expand Up @@ -116,6 +158,27 @@ const sourceAction = new codepipeline_actions.S3SourceAction({
});
```

The S3 source action produces variables:

```typescript
const s3SourceVariables = new codepipeline_actions.S3SourceVariables();
const sourceAction = new codepipeline_actions.S3SourceAction({
// ...
variables: s3SourceVariables,
});

// later:

new codepipeline_actions.CodeBuildAction({
// ...
environmentVariables: {
VERSION_ID: {
value: s3SourceVariables.versionId,
},
},
});
```

#### AWS ECR

To use an ECR Repository as a source in a Pipeline:
Expand All @@ -137,6 +200,27 @@ pipeline.addStage({
});
```

The ECR source action produces variables:

```typescript
const ecrSourceVariables = new codepipeline_actions.EcrSourceVariables();
const sourceAction = new codepipeline_actions.EcrSourceAction({
// ...
variables: ecrSourceVariables,
});

// later:

new codepipeline_actions.CodeBuildAction({
// ...
environmentVariables: {
IMAGE_URI: {
value: ecrSourceVariables.imageUri,
},
},
});
```

### Build & test

#### AWS CodeBuild
Expand Down Expand Up @@ -266,6 +350,49 @@ const project = new codebuild.PipelineProject(this, 'MyProject', {
});
```

##### Variables

The CodeBuild action emits variables.
Unlike many other actions, the variables are not static,
but dynamic, defined in the buildspec,
in the 'exported-variables' subsection of the 'env' section.
Example:

```typescript
const codeBuildVariables = new codepipeline_actions.CodeBuildVariables();
new codepipeline_actions.CodeBuildAction({
actionName: 'Build1',
input: sourceOutput,
project: new codebuild.PipelineProject(this, 'Project', {
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
env: {
'exported-variables': [
'MY_VAR',
],
},
phases: {
build: {
commands: 'export MY_VAR="some value"',
},
},
}),
}),
variables: codeBuildVariables,
});

// later:

new codepipeline_actions.CodeBuildAction({
// ...
environmentVariables: {
MyVar: {
value: codeBuildVariables.variable('MY_VAR'),
},
},
});
```

#### Jenkins

In order to use Jenkins Actions in the Pipeline,
Expand Down Expand Up @@ -304,7 +431,7 @@ const buildAction = new codepipeline_actions.JenkinsAction({
actionName: 'JenkinsBuild',
jenkinsProvider: jenkinsProvider,
projectName: 'MyProject',
type: ccodepipeline_actions.JenkinsActionType.BUILD,
type: codepipeline_actions.JenkinsActionType.BUILD,
});
```

Expand Down Expand Up @@ -421,7 +548,7 @@ const func = new lambda.Function(lambdaStack, 'Lambda', {
runtime: lambda.Runtime.NODEJS_8_10,
});
// used to make sure each CDK synthesis produces a different Version
const version = func.addVersion('NewVersion')
const version = func.addVersion('NewVersion');
const alias = new lambda.Alias(lambdaStack, 'LambdaAlias', {
aliasName: 'Prod',
version,
Expand Down Expand Up @@ -598,5 +725,50 @@ const lambdaAction = new codepipeline_actions.LambdaInvokeAction({
});
```

The Lambda invoke action emits variables.
Unlike many other actions, the variables are not static,
but dynamic, defined by the function calling the `PutJobSuccessResult`
API with the `outputVariables` property filled with the map of variables
Example:

```typescript
import lambda = require('@aws-cdk/aws-lambda');

const lambdaInvokeVariables = new codepipeline_actions.LambdaInvokeVariables();
new codepipeline_actions.LambdaInvokeAction({
actionName: 'Lambda',
lambda: new lambda.Function(this, 'Func', {
runtime: lambda.Runtime.NODEJS_10_X,
handler: 'index.handler',
code: lambda.Code.fromInline(`
var AWS = require('aws-sdk');
exports.handler = function (event, context) {
var codepipeline = new AWS.CodePipeline();
codepipeline.putJobSuccessResult({
jobId: event['CodePipeline.job'].id,
outputVariables: {
MY_VAR: "some value",
},
});
context.succeed("success");
}
`),
}),
variables: lambdaInvokeVariables,
});

// later:

new codepipeline_actions.CodeBuildAction({
// ...
environmentVariables: {
MyVar: {
value: lambdaInvokeVariables.variable('MY_VAR'),
},
},
});
```

See [the AWS documentation](https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html)
on how to write a Lambda function invoked from CodePipeline.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export enum CodeBuildActionType {
}

/**
* The CodePipeline variables for the CodeBuild Action.
* The CodePipeline variables emitted by the CodeBuild Action.
*/
export class CodeBuildVariables extends codepipeline.Variables {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export enum CodeCommitTrigger {
}

/**
* The CodePipeline variables for the CodeCommit source Action.
* The CodePipeline variables emitted by the CodeCommit source Action.
*/
export class CodeCommitSourceVariables extends codepipeline.Variables {
/** The name of the repository this action points to. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Action } from '../action';
import { sourceArtifactBounds } from '../common';

/**
* The CodePipeline variables for the ECR source Action.
* The CodePipeline variables emitted by the ECR source Action.
*/
export class EcrSourceVariables extends codepipeline.Variables {
/** The identifier of the registry. In ECR, this is usually the ID of the AWS account owning it. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export enum GitHubTrigger {
}

/**
* The CodePipeline variables for the GitHub source Action.
* The CodePipeline variables emitted by GitHub source Action.
*/
export class GitHubSourceVariables extends codepipeline.Variables {
/** The name of the repository this action points to. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Construct, Stack } from "@aws-cdk/core";
import { Action } from '../action';

/**
* The CodePipeline variables for the Lambda invoke Action.
* The CodePipeline variables emitted by the Lambda invoke Action.
*/
export class LambdaInvokeVariables extends codepipeline.Variables {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export enum S3Trigger {
}

/**
* The CodePipeline variables for the S3 source Action.
* The CodePipeline variables emitted by the S3 source Action.
*/
export class S3SourceVariables extends codepipeline.Variables {
/** The identifier of the S3 version of the object that triggered the build. */
Expand Down
37 changes: 36 additions & 1 deletion packages/@aws-cdk/aws-codepipeline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ sourceStage.addAction(someAction);
### Cross-region CodePipelines

You can also use the cross-region feature to deploy resources
(currently, only CloudFormation Stacks are supported)
into a different region than your Pipeline is in.

It works like this:
Expand Down Expand Up @@ -180,6 +179,42 @@ const replicationBucket = new s3.Bucket(replicationStack, 'ReplicationBucket', {
});
```

### Variables

The construct supports the variables feature.
Each action class that emits variables has a separate variables class.
You instantiate the class and assign it to a local variable,
then pass it in the `variables` property when creating the action producing the variables.
When you want to use a variable in the configuration of a different action,
you use one of the properties of that local variable.
Example:

```typescript
const myActionVariables = new MyActionVariables();
const myAction = new MyAction({
// ...
variables: myActionVariables,
});
new OtherAction({
// ...
config: myActionVariables.myVariable,
});
```

The namespace name that will be used will be automatically generated by the pipeline construct,
based on the stage and action name;
you can pass a custom name when creating the variables instance:

```typescript
const myActionVariables = new MyActionVariables('MyNamespace');
```

Check the documentation of the `@aws-cdk/aws-codepipeline-actions`
for details on how to use the variables for each action class.

See the [CodePipeline documentation](https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-variables.html)
for more details on how to use the variables feature.

### Events

#### Using a pipeline as an event target
Expand Down

0 comments on commit 88ca213

Please sign in to comment.