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:

new pipelines.CodeBuildStep('Synth', {
commands: ['./build.sh'],
});

Hierarchy (view full)

Constructors

Properties

actionRole?: IRole

Custom execution role to be used for the Code Build Action

- A role is automatically created
buildEnvironment?: BuildEnvironment

Build environment

- No value specified at construction time, use defaults
cache?: Cache

Caching strategy to use.

- No cache
commands: string[]

Commands to run

dependencyFileSets: FileSet[]

The list of FileSets consumed by this Step

env: Record<string, string>

Environment variables to set

- No environment variables
envFromCfnOutputs: Record<string, StackOutputReference>

Set environment variables based on Stack Outputs

- No environment variables created from stack outputs
fileSystemLocations?: IFileSystemLocation[]

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.

- no file system locations
id: string

Identifier for this step

inputs: FileSetLocation[]

Input FileSets

A list of (FileSet, directory) pairs, which are a copy of the input properties. This list should not be modified directly.

installCommands: string[]

Installation commands to run before the regular commands

For deployment engines that support it, install commands will be classified differently in the job history from the regular commands.

- No installation commands
isSource: boolean

Whether or not this is a Source step

What it means to be a Source step depends on the engine.

logging?: LoggingOptions

Information about logs for CodeBuild projects. A CodeBuilde project can create logs in Amazon CloudWatch Logs, an S3 bucket, or both.

- no log configuration is set
outputs: FileSetLocation[]

Output FileSets

A list of (FileSet, directory) pairs, which are a copy of the input properties. This list should not be modified directly.

projectName?: string

Name for the generated CodeBuild project

- No value specified at construction time, use defaults
role?: IRole

Custom execution role to be used for the CodeBuild project

- No value specified at construction time, use defaults
rolePolicyStatements?: PolicyStatement[]

Policy statements to add to role used during the synth

- No value specified at construction time, use defaults
securityGroups?: ISecurityGroup[]

Which security group to associate with the script's project network interfaces.

- No value specified at construction time, use defaults
subnetSelection?: SubnetSelection

Which subnets to use.

- No value specified at construction time, use defaults
timeout?: Duration

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.

Duration.hours(1)
vpc?: IVpc

The VPC where to execute the SimpleSynth.

- No value specified at construction time, use defaults

Accessors

  • get consumedStackOutputs(): StackOutputReference[]
  • StackOutputReferences this step consumes.

    Returns StackOutputReference[]

  • get dependencies(): Step[]
  • Return the steps this step depends on, based on the FileSets it requires

    Returns Step[]

  • get grantPrincipal(): IPrincipal
  • The CodeBuild Project's principal

    Returns IPrincipal

  • get partialBuildSpec(): undefined | BuildSpec
  • Additional configuration that can only be configured via BuildSpec

    Contains exported variables

    Returns undefined | BuildSpec

    - Contains the exported variables
    
  • get primaryOutput(): undefined | FileSet
  • The primary FileSet produced by this Step

    Not all steps produce an output FileSet--if they do you can substitute the Step object for the FileSet object.

    Returns undefined | FileSet

  • get project(): IProject
  • CodeBuild Project generated for the pipeline

    Will only be available after the pipeline has been built.

    Returns IProject

Methods

  • Internal

    Set the internal project value

    Parameters

    • project: IProject

    Returns void

  • Add an additional FileSet to the set of file sets required by this step

    This will lead to a dependency on the producer of that file set.

    Parameters

    Returns void

  • Add an additional output FileSet based on a directory.

    After running the script, the contents of the given directory will be exported as a FileSet. Use the FileSet as the input to another step.

    Multiple calls with the exact same directory name string (not normalized) will return the same FileSet.

    Parameters

    • directory: string

    Returns FileSet

  • Add a dependency on another step.

    Parameters

    Returns void

  • Configure the given FileSet as the primary output of this step

    Parameters

    Returns void

  • Crawl the given structure for references to StepOutputs and add dependencies on all steps found

    Should be called in the constructor of subclasses based on what the user passes in as construction properties. The format of the structure passed in here does not have to correspond exactly to what gets rendered into the engine, it just needs to contain the same data.

    Parameters

    • structure: any

    Returns void

  • 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.

    Parameters

    • variableName: string

      the name of the variable for reference.

    Returns string

    // Access the output of one CodeBuildStep in another CodeBuildStep
    declare const pipeline: pipelines.CodePipeline;

    const step1 = new pipelines.CodeBuildStep('Step1', {
    commands: ['export MY_VAR=hello'],
    });

    const step2 = new pipelines.CodeBuildStep('Step2', {
    env: {
    IMPORTED_VAR: step1.exportedVariable('MY_VAR'),
    },
    commands: ['echo $IMPORTED_VAR'],
    });
  • Configure the given output directory as primary output

    If no primary output has been configured yet, this directory will become the primary output of this ShellStep, otherwise this method will throw if the given directory is different than the currently configured primary output directory.

    Parameters

    • directory: string

    Returns FileSet

  • Return a string representation of this Step

    Returns string

  • Define a sequence of steps to be executed in order.

    If you need more fine-grained step ordering, use the addStepDependency() API. For example, if you want secondStep to occur after firstStep, call secondStep.addStepDependency(firstStep).

    Parameters

    Returns Step[]