Class CodeBuildStep

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

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:49.783Z") @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.Builder.create(this, "Pipeline")
         .synth(CodeBuildStep.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", "..."))
                 .rolePolicyStatements(List.of(
                     PolicyStatement.Builder.create()
                             .actions(List.of("sts:AssumeRole"))
                             .resources(List.of("*"))
                             .conditions(Map.of(
                                     "StringEquals", Map.of(
                                             "iam:ResourceTag/aws-cdk:bootstrap-role", "lookup")))
                             .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 - 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

    • 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