class CodeBuildStep
Language | Type name |
---|---|
.NET | Amazon.CDK.Pipelines.CodeBuildStep |
Java | software.amazon.awscdk.pipelines.CodeBuildStep |
Python | aws_cdk.pipelines.CodeBuildStep |
TypeScript (source) | @aws-cdk/pipelines » CodeBuildStep |
Implements
IFile
Extends
Shell
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'],
});
Example
new pipelines.CodePipeline(this, 'Pipeline', {
synth: new pipelines.CodeBuildStep('Synth', {
input: pipelines.CodePipelineSource.connection('my-org/my-app', 'main', {
connectionArn: 'arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41', // Created using the AWS console * });',
}),
commands: [
// Commands to load cdk.context.json from somewhere here
'...',
'npm ci',
'npm run build',
'npx cdk synth',
// Commands to store cdk.context.json back here
'...',
],
rolePolicyStatements: [
new iam.PolicyStatement({
actions: ['sts:AssumeRole'],
resources: ['*'],
conditions: {
StringEquals: {
'iam:ResourceTag/aws-cdk:bootstrap-role': 'lookup',
},
},
}),
],
}),
});
Initializer
new CodeBuildStep(id: string, props: CodeBuildStepProps)
Parameters
- id
string
- props
Code
Build Step Props
Properties
Name | Type | Description |
---|---|---|
commands | string[] | Commands to run. |
dependencies | Step [] | Return the steps this step depends on, based on the FileSets it requires. |
dependency | File [] | The list of FileSets consumed by this Step. |
env | { [string]: string } | Environment variables to set. |
env | { [string]: Stack } | Set environment variables based on Stack Outputs. |
grant | IPrincipal | The CodeBuild Project's principal. |
id | string | Identifier for this step. |
inputs | File [] | Input FileSets. |
install | string[] | Installation commands to run before the regular commands. |
is | boolean | Whether or not this is a Source step. |
outputs | File [] | Output FileSets. |
project | IProject | CodeBuild Project generated for the pipeline. |
action | IRole | Custom execution role to be used for the Code Build Action. |
build | Build | Build environment. |
partial | Build | Additional configuration that can only be configured via BuildSpec. |
primary | File | The primary FileSet produced by this Step. |
project | string | Name for the generated CodeBuild project. |
role? | IRole | Custom execution role to be used for the CodeBuild project. |
role | Policy [] | Policy statements to add to role used during the synth. |
security | ISecurity [] | Which security group to associate with the script's project network interfaces. |
subnet | Subnet | Which subnets to use. |
timeout? | Duration | The number of minutes after which AWS CodeBuild stops the build if it's not complete. |
vpc? | IVpc | The VPC where to execute the SimpleSynth. |
commands
Type:
string[]
Commands to run.
dependencies
Type:
Step
[]
Return the steps this step depends on, based on the FileSets it requires.
dependencyFileSets
Type:
File
[]
The list of FileSets consumed by this Step.
env
Type:
{ [string]: string }
Environment variables to set.
envFromCfnOutputs
Type:
{ [string]:
Stack
}
Set environment variables based on Stack Outputs.
grantPrincipal
Type:
IPrincipal
The CodeBuild Project's principal.
id
Type:
string
Identifier for this step.
inputs
Type:
File
[]
Input FileSets.
A list of (FileSet, directory)
pairs, which are a copy of the
input properties. This list should not be modified directly.
installCommands
Type:
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
.
isSource
Type:
boolean
Whether or not this is a Source step.
What it means to be a Source step depends on the engine.
outputs
Type:
File
[]
Output FileSets.
A list of (FileSet, directory)
pairs, which are a copy of the
input properties. This list should not be modified directly.
project
Type:
IProject
CodeBuild Project generated for the pipeline.
Will only be available after the pipeline has been built.
actionRole?
Type:
IRole
(optional, default: A role is automatically created)
Custom execution role to be used for the Code Build Action.
buildEnvironment?
Type:
Build
(optional, default: No value specified at construction time, use defaults)
Build environment.
partialBuildSpec?
Type:
Build
(optional, default: Contains the exported variables)
Additional configuration that can only be configured via BuildSpec.
Contains exported variables
primaryOutput?
Type:
File
(optional)
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.
projectName?
Type:
string
(optional, default: No value specified at construction time, use defaults)
Name for the generated CodeBuild project.
role?
Type:
IRole
(optional, default: No value specified at construction time, use defaults)
Custom execution role to be used for the CodeBuild project.
rolePolicyStatements?
Type:
Policy
[]
(optional, default: No value specified at construction time, use defaults)
Policy statements to add to role used during the synth.
securityGroups?
Type:
ISecurity
[]
(optional, default: No value specified at construction time, use defaults)
Which security group to associate with the script's project network interfaces.
subnetSelection?
Type:
Subnet
(optional, default: No value specified at construction time, use defaults)
Which subnets to use.
timeout?
Type:
Duration
(optional, default: Duration.hours(1))
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.
vpc?
Type:
IVpc
(optional, default: No value specified at construction time, use defaults)
The VPC where to execute the SimpleSynth.
Methods
Name | Description |
---|---|
add | Add an additional output FileSet based on a directory. |
add | Add a dependency on another step. |
exported | Reference a CodePipeline variable defined by the CodeBuildStep. |
primary | Configure the given output directory as primary output. |
to | Return a string representation of this Step. |
addOutputDirectory(directory)
public addOutputDirectory(directory: string): FileSet
Parameters
- directory
string
Returns
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.
addStepDependency(step)
public addStepDependency(step: Step): void
Parameters
- step
Step
Add a dependency on another step.
exportedVariable(variableName)
public exportedVariable(variableName: string): string
Parameters
- variableName
string
— the name of the variable for reference.
Returns
string
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
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'],
});
primaryOutputDirectory(directory)
public primaryOutputDirectory(directory: string): FileSet
Parameters
- directory
string
Returns
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.
toString()
public toString(): string
Returns
string
Return a string representation of this Step.