Bases: 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:
pipelines.CodeBuildStep("Synth",
commands=["./build.sh"]
)
infused
Example:
pipelines.CodePipeline(self, "Pipeline",
synth=pipelines.CodeBuildStep("Synth",
input=pipelines.CodePipelineSource.connection("my-org/my-app", "main",
connection_arn="arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41"
),
commands=["...", "npm ci", "npm run build", "npx cdk synth", "..."
],
role_policy_statements=[
iam.PolicyStatement(
actions=["sts:AssumeRole"],
resources=["*"],
conditions={
"StringEquals": {
"iam:ResourceTag/aws-cdk:bootstrap-role": "lookup"
}
}
)
]
)
)
id (str
)
action_role (Optional
[IRole
]) – Custom execution role to be used for the Code Build Action. Default: - A role is automatically created
build_environment (Union
[BuildEnvironment
, Dict
[str
, Any
], None
]) – Changes to environment. This environment will be combined with the pipeline’s default environment. Default: - Use the pipeline’s default build environment
partial_build_spec (Optional
[BuildSpec
]) – Additional configuration that can only be configured via BuildSpec. You should not use this to specify output artifacts; those should be supplied via the other properties of this class, otherwise CDK Pipelines won’t be able to inspect the artifacts. Set the commands
to an empty array if you want to fully specify the BuildSpec using this field. The BuildSpec must be available inline–it cannot reference a file on disk. Default: - BuildSpec completely derived from other properties
project_name (Optional
[str
]) – Name for the generated CodeBuild project. Default: - Automatically generated
role (Optional
[IRole
]) – Custom execution role to be used for the CodeBuild project. Default: - A role is automatically created
role_policy_statements (Optional
[Sequence
[PolicyStatement
]]) – Policy statements to add to role used during the synth. Can be used to add acces to a CodeArtifact repository etc. Default: - No policy statements added to CodeBuild Project Role
security_groups (Optional
[Sequence
[ISecurityGroup
]]) – Which security group to associate with the script’s project network interfaces. If no security group is identified, one will be created automatically. Only used if ‘vpc’ is supplied. Default: - Security group will be automatically created.
subnet_selection (Union
[SubnetSelection
, Dict
[str
, Any
], None
]) – Which subnets to use. Only used if ‘vpc’ is supplied. Default: - All private subnets.
timeout (Optional
[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. Default: Duration.hours(1)
vpc (Optional
[IVpc
]) – The VPC where to execute the SimpleSynth. Default: - No VPC
commands (Sequence
[str
]) – Commands to run.
additional_inputs (Optional
[Mapping
[str
, IFileSetProducer
]]) – Additional FileSets to put in other directories. Specifies a mapping from directory name to FileSets. During the script execution, the FileSets will be available in the directories indicated. The directory names may be relative. For example, you can put the main input and an additional input side-by-side with the following configuration:: const script = new pipelines.ShellStep(‘MainScript’, { commands: [‘npm ci’,’npm run build’,’npx cdk synth’], input: pipelines.CodePipelineSource.gitHub(‘org/source1’, ‘main’), additionalInputs: { ‘../siblingdir’: pipelines.CodePipelineSource.gitHub(‘org/source2’, ‘main’), } }); Default: - No additional inputs
env (Optional
[Mapping
[str
, str
]]) – Environment variables to set. Default: - No environment variables
env_from_cfn_outputs (Optional
[Mapping
[str
, CfnOutput
]]) – Set environment variables based on Stack Outputs. ``ShellStep``s following stack or stage deployments may access the ``CfnOutput``s of those stacks to get access to –for example–automatically generated resource names or endpoint URLs. Default: - No environment variables created from stack outputs
input (Optional
[IFileSetProducer
]) – FileSet to run these scripts on. The files in the FileSet will be placed in the working directory when the script is executed. Use additionalInputs
to download file sets to other directories as well. Default: - No input specified
install_commands (Optional
[Sequence
[str
]]) – 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
. Default: - No installation commands
primary_output_directory (Optional
[str
]) – The directory that will contain the primary output fileset. After running the script, the contents of the given directory will be treated as the primary output of this Step. Default: - No primary output
Methods
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.
directory (str
)
Add a dependency on another step.
step (Step
)
None
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.
variable_name (str
) – the name of the variable for reference.
str
Example:
# Access the output of one CodeBuildStep in another CodeBuildStep
# pipeline: pipelines.CodePipeline
step1 = pipelines.CodeBuildStep("Step1",
commands=["export MY_VAR=hello"]
)
step2 = pipelines.CodeBuildStep("Step2",
env={
"IMPORTED_VAR": step1.exported_variable("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.
directory (str
)
Return a string representation of this Step.
str
Attributes
Custom execution role to be used for the Code Build Action.
A role is automatically created
Build environment.
No value specified at construction time, use defaults
Commands to run.
Return the steps this step depends on, based on the FileSets it requires.
The list of FileSets consumed by this Step.
Environment variables to set.
No environment variables
Set environment variables based on Stack Outputs.
No environment variables created from stack outputs
The CodeBuild Project’s principal.
Identifier for this step.
Input FileSets.
A list of (FileSet, directory)
pairs, which are a copy of the
input properties. This list should not be modified directly.
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
Whether or not this is a Source step.
What it means to be a Source step depends on the engine.
Output FileSets.
A list of (FileSet, directory)
pairs, which are a copy of the
input properties. This list should not be modified directly.
Additional configuration that can only be configured via BuildSpec.
Contains exported variables
Contains the exported variables
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.
CodeBuild Project generated for the pipeline.
Will only be available after the pipeline has been built.
Name for the generated CodeBuild project.
No value specified at construction time, use defaults
Custom execution role to be used for the CodeBuild project.
No value specified at construction time, use defaults
Policy statements to add to role used during the synth.
No value specified at construction time, use defaults
Which security group to associate with the script’s project network interfaces.
No value specified at construction time, use defaults
Which subnets to use.
No value specified at construction time, use defaults
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)
The VPC where to execute the SimpleSynth.
No value specified at construction time, use defaults
Static Methods
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)
.