Create a build specification file and include it with your source code. In this file,
specify the commands you want to run in each phase of the build lifecycle. For
more information, see the
Build specification reference for CodeBuild
.
Use the CodeBuild console to create a build project. In
Insert build commands
, for
Build commands
,
enter the commands you want to run in the
build
phase. For more information, see
Create a build project (console)
.
Use the CodeBuild console to change the settings of a build project. In
Insert build commands
, for
Build
commands
, enter the commands you want to run in the
build
phase. For more information, see
Change a build project's settings
(console)
.
Use the AWS CLI or AWS SDKs to create a build project or change the settings
of a build project. Reference the source code that contains a buildspec file
with your commands, or specify a single string that includes the contents of an
equivalent buildspec file. For more information, see
Create a build project
or
Change build project settings
.
Use the AWS CLI or AWS SDKs to start a build, specifying a buildspec file or
a single string that includes the contents of an equivalent buildspec file. For
more information, see the description for the
buildspecOverride
value in
Run builds manually
.
You can specify any Shell Command Language (sh) command. In buildspec version 0.1, CodeBuild runs each Shell
command in a separate instance in the build environment. This means that each command
runs in isolation from all other commands. Therefore, by default, you cannot run a
single command that relies on the state of any previous commands (for example, changing
directories or setting environment variables). To get around this limitation, we
recommend that you use version 0.2, which solves this issue. If you must use version 0.1, we recommend the following approaches:
Include a shell script in your source code that contains the commands you want
to run in a single instance of the default shell. For example, you could include
a file named
my-script.sh
in your source code that contains
commands such as
cd MyDir; mkdir -p mySubDir; cd mySubDir; pwd;
.
Then, in your buildspec file, specify the command
./my-script.sh
.