Class CodeBuildStep

java.lang.Object
software.amazon.jsii.JsiiObject
All Implemented Interfaces:
IFileSetProducer, software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.98.0 (build 00b106d)", date="2024-05-17T05:10:19.418Z") @Stability(Stable) public class CodeBuildStep extends ShellStep
Run a script as a CodeBuild Project.

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());
 
  • Constructor Details

    • CodeBuildStep

      protected CodeBuildStep(software.amazon.jsii.JsiiObjectRef objRef)
    • CodeBuildStep

      protected CodeBuildStep(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • CodeBuildStep

      @Stability(Stable) public CodeBuildStep(@NotNull String id, @NotNull CodeBuildStepProps props)
      Parameters:
      id - Identifier for this step. This parameter is required.
      props - This parameter is required.
  • Method Details

    • exportedVariable

      @Stability(Stable) @NotNull public String exportedVariable(@NotNull String variableName)
      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

      @Stability(Stable) @NotNull public IPrincipal getGrantPrincipal()
      The CodeBuild Project's principal.
    • getProject

      @Stability(Stable) @NotNull public IProject getProject()
      CodeBuild Project generated for the pipeline.

      Will only be available after the pipeline has been built.

    • getActionRole

      @Stability(Stable) @Nullable public IRole getActionRole()
      Custom execution role to be used for the Code Build Action.

      Default: - A role is automatically created

    • getBuildEnvironment

      @Stability(Stable) @Nullable public BuildEnvironment getBuildEnvironment()
      Build environment.

      Default: - No value specified at construction time, use defaults

    • getCache

      @Stability(Stable) @Nullable public Cache getCache()
      Caching strategy to use.

      Default: - No cache

    • getFileSystemLocations

      @Stability(Stable) @Nullable public List<IFileSystemLocation> 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

      @Stability(Stable) @Nullable public LoggingOptions 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

      @Stability(Stable) @Nullable public BuildSpec getPartialBuildSpec()
      Additional configuration that can only be configured via BuildSpec.

      Contains exported variables

      Default: - Contains the exported variables

    • getProjectName

      @Stability(Stable) @Nullable public String getProjectName()
      Name for the generated CodeBuild project.

      Default: - No value specified at construction time, use defaults

    • getRole

      @Stability(Stable) @Nullable public IRole getRole()
      Custom execution role to be used for the CodeBuild project.

      Default: - No value specified at construction time, use defaults

    • getRolePolicyStatements

      @Stability(Stable) @Nullable public List<PolicyStatement> getRolePolicyStatements()
      Policy statements to add to role used during the synth.

      Default: - No value specified at construction time, use defaults

    • getSecurityGroups

      @Stability(Stable) @Nullable public List<ISecurityGroup> getSecurityGroups()
      Which security group to associate with the script's project network interfaces.

      Default: - No value specified at construction time, use defaults

    • getSubnetSelection

      @Stability(Stable) @Nullable public SubnetSelection getSubnetSelection()
      Which subnets to use.

      Default: - No value specified at construction time, use defaults

    • getTimeout

      @Stability(Stable) @Nullable public Duration 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

      @Stability(Stable) @Nullable public IVpc getVpc()
      The VPC where to execute the SimpleSynth.

      Default: - No value specified at construction time, use defaults