CodeBuild client
This page contains examples with the CodeBuild client. See the client introduction for a more detailed description how to use a client. You may also want to consider the authentication documentation to understand the many ways you can authenticate with AWS.
The CodeBuild package could be installed with Composer.
composer require async-aws/code-build
A new client object may be instantiated by:
use AsyncAws\CodeBuild\CodeBuildClient;
$codeBuild = new CodeBuildClient();
The authentication parameters is read from the environment by default. You can also specify a AWS access id and secret:
use AsyncAws\CodeBuild\CodeBuildClient;
$codeBuild = new CodeBuildClient([
'accessKeyId' => 'my_access_key',
'accessKeySecret' => 'my_access_secret',
'region' => 'eu-central-1',
]);
For all available options, see the configuration reference.
Usage¶
Start a build¶
use AsyncAws\CodeBuild\CodeBuildClient;
use AsyncAws\CodeBuild\Input\StartBuildInput;
$codeBuild = new CodeBuildClient();
$buildSpec = <<<EOS
version: 0.2
phases:
build:
commands:
- whoami >stdout 2>stderr
artifacts:
files:
- stdout
- stderr
EOS;
$codeBuild->startBuild(new StartBuildInput([
'projectName' => 'my-project',
'environmentVariablesOverride' => [
[
'name' => 'APP_ENV',
'type' => 'PLAINTEXT',
'value' => 'prod',
]
],
'buildspecOverride' => $buildSpec,
'timeoutInMinutesOverride' => 10,
]));
Stop a build¶
use AsyncAws\CodeBuild\CodeBuildClient;
use AsyncAws\CodeBuild\Input\StopBuildInput;
$codeBuild = new CodeBuildClient();
$response = $codeBuild->stopBuild(new StopBuildInput([
'id' => 'build-identifier',
]));
echo $response->getBuild()->getArtifacts()->getLocation();
The source code to this page is found on GitHub.