Class CodeBuildAction
CodePipeline build action that uses AWS CodeBuild.
Implements
Inherited Members
Namespace: Amazon.CDK.AWS.CodePipeline.Actions
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class CodeBuildAction : Action, IAction
Syntax (vb)
Public Class CodeBuildAction
Inherits Action
Implements IAction
Remarks
ExampleMetadata: infused
Examples
// Create a Cloudfront Web Distribution
using Amazon.CDK.AWS.CloudFront;
Distribution distribution;
// Create the build project that will invalidate the cache
var invalidateBuildProject = new PipelineProject(this, "InvalidateProject", new PipelineProjectProps {
BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
{ "version", "0.2" },
{ "phases", new Dictionary<string, IDictionary<string, string[]>> {
{ "build", new Struct {
Commands = new [] { "aws cloudfront create-invalidation --distribution-id ${CLOUDFRONT_ID} --paths \"/*\"" }
} }
} }
}),
EnvironmentVariables = new Dictionary<string, BuildEnvironmentVariable> {
{ "CLOUDFRONT_ID", new BuildEnvironmentVariable { Value = distribution.DistributionId } }
}
});
// Add Cloudfront invalidation permissions to the project
var distributionArn = $"arn:aws:cloudfront::{this.account}:distribution/{distribution.distributionId}";
invalidateBuildProject.AddToRolePolicy(new PolicyStatement(new PolicyStatementProps {
Resources = new [] { distributionArn },
Actions = new [] { "cloudfront:CreateInvalidation" }
}));
// Create the pipeline (here only the S3 deploy and Invalidate cache build)
var deployBucket = new Bucket(this, "DeployBucket");
var deployInput = new Artifact();
new Pipeline(this, "Pipeline", new PipelineProps {
Stages = new [] { new StageProps {
StageName = "Deploy",
Actions = new [] {
new S3DeployAction(new S3DeployActionProps {
ActionName = "S3Deploy",
Bucket = deployBucket,
Input = deployInput,
RunOrder = 1
}),
new CodeBuildAction(new CodeBuildActionProps {
ActionName = "InvalidateCache",
Project = invalidateBuildProject,
Input = deployInput,
RunOrder = 2
}) }
} }
});
Synopsis
Constructors
CodeBuildAction(ICodeBuildActionProps) | |
CodeBuildAction(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
CodeBuildAction(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Methods
Bound(Construct, IStage, IActionBindOptions) | This is a renamed version of the |
Variable(String) | Reference a CodePipeline variable defined by the CodeBuild project this action points to. |
Constructors
CodeBuildAction(ICodeBuildActionProps)
CodeBuildAction(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected CodeBuildAction(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
CodeBuildAction(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected CodeBuildAction(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Methods
Bound(Construct, IStage, IActionBindOptions)
This is a renamed version of the IAction.bind
method.
protected override IActionConfig Bound(Construct scope, IStage stage, IActionBindOptions options)
Parameters
- scope Constructs.Construct
- stage IStage
- options IActionBindOptions
Returns
Overrides
Variable(String)
Reference a CodePipeline variable defined by the CodeBuild project this action points to.
public virtual string Variable(string variableName)
Parameters
- variableName System.String
the name of the variable to reference.
Returns
System.String
Remarks
Variables in CodeBuild actions are defined using the 'exported-variables' subsection of the 'env' section of the buildspec.
See: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-syntax