Class CodeBuildStep
- All Implemented Interfaces:
IFileSetProducer
,software.amazon.jsii.JsiiSerializable
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:
CodeBuildStep.Builder.create("Synth") .commands(List.of("./build.sh")) .build();
Example:
CodePipeline pipeline = CodePipeline.Builder.create(this, "Pipeline") .synth(ShellStep.Builder.create("Synth") .input(CodePipelineSource.connection("my-org/my-app", "main", ConnectionSourceOptions.builder() .connectionArn("arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41") .build())) .commands(List.of("npm ci", "npm run build", "npx cdk synth")) .build()) // Turn this on because the pipeline uses Docker image assets .dockerEnabledForSelfMutation(true) .build(); pipeline.addWave("MyWave", WaveOptions.builder() .post(List.of( CodeBuildStep.Builder.create("RunApproval") .commands(List.of("command-from-image")) .buildEnvironment(BuildEnvironment.builder() // The user of a Docker image asset in the pipeline requires turning on // 'dockerEnabledForSelfMutation'. .buildImage(LinuxBuildImage.fromAsset(this, "Image", DockerImageAssetProps.builder() .directory("./docker-image") .build())) .build()) .build())) .build());
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.amazon.awscdk.pipelines.IFileSetProducer
IFileSetProducer.Jsii$Default
-
Constructor Summary
ModifierConstructorDescriptionCodeBuildStep
(String id, CodeBuildStepProps props) protected
CodeBuildStep
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
CodeBuildStep
(software.amazon.jsii.JsiiObjectRef objRef) -
Method Summary
Modifier and TypeMethodDescriptionexportedVariable
(String variableName) Reference a CodePipeline variable defined by the CodeBuildStep.Custom execution role to be used for the Code Build Action.Build environment.getCache()
Caching strategy to use.ProjectFileSystemLocation objects for CodeBuild build projects.The CodeBuild Project's principal.Information about logs for CodeBuild projects.Additional configuration that can only be configured via BuildSpec.CodeBuild Project generated for the pipeline.Name for the generated CodeBuild project.getRole()
Custom execution role to be used for the CodeBuild project.Policy statements to add to role used during the synth.Which security group to associate with the script's project network interfaces.Which subnets to use.The number of minutes after which AWS CodeBuild stops the build if it's not complete.getVpc()
The VPC where to execute the SimpleSynth.Methods inherited from class software.amazon.awscdk.pipelines.ShellStep
addOutputDirectory, getCommands, getConsumedStackOutputs, getEnv, getEnvFromCfnOutputs, getInputs, getInstallCommands, getOutputs, primaryOutputDirectory
Methods inherited from class software.amazon.awscdk.pipelines.Step
addDependencyFileSet, addStepDependency, configurePrimaryOutput, discoverReferencedOutputs, getDependencies, getDependencyFileSets, getId, getIsSource, getPrimaryOutput, sequence, toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
CodeBuildStep
protected CodeBuildStep(software.amazon.jsii.JsiiObjectRef objRef) -
CodeBuildStep
protected CodeBuildStep(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
CodeBuildStep
- Parameters:
id
- Identifier for this step. This parameter is required.props
- This parameter is required.
-
-
Method Details
-
exportedVariable
Reference a CodePipeline variable defined by the CodeBuildStep.The variable must be set in the shell of the CodeBuild step when it finishes its
post_build
phase.Example:
// Access the output of one CodeBuildStep in another CodeBuildStep CodePipeline pipeline; CodeBuildStep step1 = CodeBuildStep.Builder.create("Step1") .commands(List.of("export MY_VAR=hello")) .build(); CodeBuildStep step2 = CodeBuildStep.Builder.create("Step2") .env(Map.of( "IMPORTED_VAR", step1.exportedVariable("MY_VAR"))) .commands(List.of("echo $IMPORTED_VAR")) .build();
- Parameters:
variableName
- the name of the variable for reference. This parameter is required.
-
getGrantPrincipal
The CodeBuild Project's principal. -
getProject
CodeBuild Project generated for the pipeline.Will only be available after the pipeline has been built.
-
getActionRole
Custom execution role to be used for the Code Build Action.Default: - A role is automatically created
-
getBuildEnvironment
Build environment.Default: - No value specified at construction time, use defaults
-
getCache
Caching strategy to use.Default: - No cache
-
getFileSystemLocations
ProjectFileSystemLocation objects for CodeBuild build projects.A ProjectFileSystemLocation object specifies the identifier, location, mountOptions, mountPoint, and type of a file system created using Amazon Elastic File System.
Default: - no file system locations
-
getLogging
Information about logs for CodeBuild projects.A CodeBuilde project can create logs in Amazon CloudWatch Logs, an S3 bucket, or both.
Default: - no log configuration is set
-
getPartialBuildSpec
Additional configuration that can only be configured via BuildSpec.Contains exported variables
Default: - Contains the exported variables
-
getProjectName
Name for the generated CodeBuild project.Default: - No value specified at construction time, use defaults
-
getRole
Custom execution role to be used for the CodeBuild project.Default: - No value specified at construction time, use defaults
-
getRolePolicyStatements
Policy statements to add to role used during the synth.Default: - No value specified at construction time, use defaults
-
getSecurityGroups
Which security group to associate with the script's project network interfaces.Default: - No value specified at construction time, use defaults
-
getSubnetSelection
Which subnets to use.Default: - No value specified at construction time, use defaults
-
getTimeout
The number of minutes after which AWS CodeBuild stops the build if it's not complete.For valid values, see the timeoutInMinutes field in the AWS CodeBuild User Guide.
Default: Duration.hours(1)
-
getVpc
The VPC where to execute the SimpleSynth.Default: - No value specified at construction time, use defaults
-