aws-cdk-lib.aws_codepipeline_actions.CodeBuildAction

class CodeBuildAction

LanguageType name
.NETAmazon.CDK.AWS.CodePipeline.Actions.CodeBuildAction
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awscodepipelineactions#CodeBuildAction
Javasoftware.amazon.awscdk.services.codepipeline.actions.CodeBuildAction
Pythonaws_cdk.aws_codepipeline_actions.CodeBuildAction
TypeScript (source)aws-cdk-lib » aws_codepipeline_actions » CodeBuildAction

Implements IAction

Extends Action

CodePipeline build action that uses AWS CodeBuild.

Example

// Create a Cloudfront Web Distribution
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
declare const distribution: cloudfront.Distribution;

// Create the build project that will invalidate the cache
const invalidateBuildProject = new codebuild.PipelineProject(this, `InvalidateProject`, {
  buildSpec: codebuild.BuildSpec.fromObject({
    version: '0.2',
    phases: {
      build: {
        commands:[
          'aws cloudfront create-invalidation --distribution-id ${CLOUDFRONT_ID} --paths "/*"',
          // Choose whatever files or paths you'd like, or all files as specified here
        ],
      },
    },
  }),
  environmentVariables: {
    CLOUDFRONT_ID: { value: distribution.distributionId },
  },
});

// Add Cloudfront invalidation permissions to the project
const distributionArn = `arn:aws:cloudfront::${this.account}:distribution/${distribution.distributionId}`;
invalidateBuildProject.addToRolePolicy(new iam.PolicyStatement({
  resources: [distributionArn],
  actions: [
    'cloudfront:CreateInvalidation',
  ],
}));

// Create the pipeline (here only the S3 deploy and Invalidate cache build)
const deployBucket = new s3.Bucket(this, 'DeployBucket');
const deployInput = new codepipeline.Artifact();
new codepipeline.Pipeline(this, 'Pipeline', {
  stages: [
    // ...
    {
      stageName: 'Deploy',
      actions: [
        new codepipeline_actions.S3DeployAction({
          actionName: 'S3Deploy',
          bucket: deployBucket,
          input: deployInput,
          runOrder: 1,
        }),
        new codepipeline_actions.CodeBuildAction({
          actionName: 'InvalidateCache',
          project: invalidateBuildProject,
          input: deployInput,
          runOrder: 2,
        }),
      ],
    },
  ],
});

Initializer

new CodeBuildAction(props: CodeBuildActionProps)

Parameters

  • props CodeBuildActionProps

Properties

NameTypeDescription
actionPropertiesActionPropertiesThe simple properties of the Action, like its Owner, name, etc.

actionProperties

Type: ActionProperties

The simple properties of the Action, like its Owner, name, etc.

Note that this accessor will be called before the bind callback.

Methods

NameDescription
bind(scope, stage, options)The callback invoked when this Action is added to a Pipeline.
onStateChange(name, target?, options?)Creates an Event that will be triggered whenever the state of this Action changes.
variable(variableName)Reference a CodePipeline variable defined by the CodeBuild project this action points to.
protected bound(scope, _stage, options)This is a renamed version of the IAction.bind method.

bind(scope, stage, options)

public bind(scope: Construct, stage: IStage, options: ActionBindOptions): ActionConfig

Parameters

  • scope Construct
  • stage IStage
  • options ActionBindOptions

Returns

  • ActionConfig

The callback invoked when this Action is added to a Pipeline.


onStateChange(name, target?, options?)

public onStateChange(name: string, target?: IRuleTarget, options?: RuleProps): Rule

Parameters

  • name string
  • target IRuleTarget
  • options RuleProps

Returns

  • Rule

Creates an Event that will be triggered whenever the state of this Action changes.


variable(variableName)

public variable(variableName: string): string

Parameters

  • variableName string — the name of the variable to reference.

Returns

  • string

Reference a CodePipeline variable defined by the CodeBuild project this action points to.

Variables in CodeBuild actions are defined using the 'exported-variables' subsection of the 'env' section of the buildspec.

See also: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-syntax


protected bound(scope, _stage, options)

protected bound(scope: Construct, _stage: IStage, options: ActionBindOptions): ActionConfig

Parameters

  • scope Construct
  • _stage IStage
  • options ActionBindOptions

Returns

  • ActionConfig

This is a renamed version of the IAction.bind method.