Class CodeBuildStep
Run a script as a CodeBuild Project.
Implements
Inherited Members
Namespace: Amazon.CDK.Pipelines
Assembly: Amazon.CDK.Pipelines.dll
Syntax (csharp)
public class CodeBuildStep : ShellStep, IFileSetProducer
Syntax (vb)
Public Class CodeBuildStep
Inherits ShellStep
Implements IFileSetProducer
Remarks
The BuildSpec must be available inline--it cannot reference a file
on disk. If your current build instructions are in a file like
buildspec.yml
in your repository, extract them to a script
(say, build.sh
) and invoke that script as part of the build:
new CodeBuildStep("Synth", new CodeBuildStepProps {
Commands = new [] { "./build.sh" }
});
ExampleMetadata: infused
Examples
new CodePipeline(this, "Pipeline", new CodePipelineProps {
Synth = new CodeBuildStep("Synth", new CodeBuildStepProps {
Input = CodePipelineSource.Connection("my-org/my-app", "main", new ConnectionSourceOptions {
ConnectionArn = "arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41"
}),
Commands = new [] { "...", "npm ci", "npm run build", "npx cdk synth", "..." },
RolePolicyStatements = new [] {
new PolicyStatement(new PolicyStatementProps {
Actions = new [] { "sts:AssumeRole" },
Resources = new [] { "*" },
Conditions = new Dictionary<string, object> {
{ "StringEquals", new Dictionary<string, string> {
{ "iam:ResourceTag/aws-cdk:bootstrap-role", "lookup" }
} }
}
}) }
})
});
Synopsis
Constructors
CodeBuildStep(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
CodeBuildStep(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
CodeBuildStep(String, ICodeBuildStepProps) |
Properties
ActionRole | Custom execution role to be used for the Code Build Action. |
BuildEnvironment | Build environment. |
GrantPrincipal | The CodeBuild Project's principal. |
PartialBuildSpec | Additional configuration that can only be configured via BuildSpec. |
Project | CodeBuild Project generated for the pipeline. |
ProjectName | Name for the generated CodeBuild project. |
Role | Custom execution role to be used for the CodeBuild project. |
RolePolicyStatements | Policy statements to add to role used during the synth. |
SecurityGroups | Which security group to associate with the script's project network interfaces. |
SubnetSelection | Which subnets to use. |
Timeout | The number of minutes after which AWS CodeBuild stops the build if it's not complete. |
Vpc | The VPC where to execute the SimpleSynth. |
Methods
ExportedVariable(String) | Reference a CodePipeline variable defined by the CodeBuildStep. |
Constructors
CodeBuildStep(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected CodeBuildStep(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
CodeBuildStep(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected CodeBuildStep(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
CodeBuildStep(String, ICodeBuildStepProps)
public CodeBuildStep(string id, ICodeBuildStepProps props)
Parameters
- id System.String
- props ICodeBuildStepProps
Properties
ActionRole
Custom execution role to be used for the Code Build Action.
public virtual IRole ActionRole { get; }
Property Value
Remarks
Default: - A role is automatically created
BuildEnvironment
Build environment.
public virtual IBuildEnvironment BuildEnvironment { get; }
Property Value
Remarks
Default: - No value specified at construction time, use defaults
GrantPrincipal
The CodeBuild Project's principal.
public virtual IPrincipal GrantPrincipal { get; }
Property Value
PartialBuildSpec
Additional configuration that can only be configured via BuildSpec.
public virtual BuildSpec PartialBuildSpec { get; }
Property Value
Remarks
Contains exported variables
Default: - Contains the exported variables
Project
CodeBuild Project generated for the pipeline.
public virtual IProject Project { get; }
Property Value
Remarks
Will only be available after the pipeline has been built.
ProjectName
Name for the generated CodeBuild project.
public virtual string ProjectName { get; }
Property Value
System.String
Remarks
Default: - No value specified at construction time, use defaults
Role
Custom execution role to be used for the CodeBuild project.
public virtual IRole Role { get; }
Property Value
Remarks
Default: - No value specified at construction time, use defaults
RolePolicyStatements
Policy statements to add to role used during the synth.
public virtual PolicyStatement[] RolePolicyStatements { get; }
Property Value
Remarks
Default: - No value specified at construction time, use defaults
SecurityGroups
Which security group to associate with the script's project network interfaces.
public virtual ISecurityGroup[] SecurityGroups { get; }
Property Value
Remarks
Default: - No value specified at construction time, use defaults
SubnetSelection
Which subnets to use.
public virtual ISubnetSelection SubnetSelection { get; }
Property Value
Remarks
Default: - No value specified at construction time, use defaults
Timeout
The number of minutes after which AWS CodeBuild stops the build if it's not complete.
public virtual Duration Timeout { get; }
Property Value
Remarks
For valid values, see the timeoutInMinutes field in the AWS CodeBuild User Guide.
Default: Duration.hours(1)
Vpc
The VPC where to execute the SimpleSynth.
public virtual IVpc Vpc { get; }
Property Value
Remarks
Default: - No value specified at construction time, use defaults
Methods
ExportedVariable(String)
Reference a CodePipeline variable defined by the CodeBuildStep.
public virtual string ExportedVariable(string variableName)
Parameters
- variableName System.String
the name of the variable for reference.
Returns
System.String
Remarks
The variable must be set in the shell of the CodeBuild step when
it finishes its post_build
phase.
Examples
// Access the output of one CodeBuildStep in another CodeBuildStep
CodePipeline pipeline;
var step1 = new CodeBuildStep("Step1", new CodeBuildStepProps {
Commands = new [] { "export MY_VAR=hello" }
});
var step2 = new CodeBuildStep("Step2", new CodeBuildStepProps {
Env = new Dictionary<string, string> {
{ "IMPORTED_VAR", step1.ExportedVariable("MY_VAR") }
},
Commands = new [] { "echo $IMPORTED_VAR" }
});