1. Go to this page and download the library: Download bbaga/buildkite-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bbaga / buildkite-php example snippets
use bbaga\BuildkiteApi\Api\RestApi;
/** @var \Psr\Http\Client\ClientInterface $client */
$client = new MyHttpClient();
$api = new RestApi($client, 'MY_BUILDKITE_API_TOKEN');
use bbaga\BuildkiteApi\Api\GraphQLApi;
/** @var \Psr\Http\Client\ClientInterface $client */
$client = new MyHttpClient();
$api = new GraphQLApi($client, 'MY_BUILDKITE_API_TOKEN');
use bbaga\BuildkiteApi\Api\GraphQLApi;
use bbaga\BuildkiteApi\Api\GuzzleClient;
$query = '
query example($slug: ID!, $first: Int){
viewer { user { name } }
organization(slug: $slug) {
pipelines(first: $first) {
edges {
node {
id
slug
}
}
}
}
}';
$variables = json_encode(['slug' => 'my-org', 'first' => 5]);
$client = new GuzzleClient();
$api = new GraphQLApi($client, 'MY_BUILDKITE_API_TOKEN');
$api->getResponseBody($api->post($query, $variables));
use bbaga\BuildkiteApi\Api\GuzzleClient;
use bbaga\BuildkiteApi\Api\Rest\Fluent;
use bbaga\BuildkiteApi\Api\RestApi;
$client = new GuzzleClient();
$api = new RestApi($client, 'MY_BUILDKITE_API_TOKEN');
/** Getting all the organizations that are visible with the TOKEN */
/** @var Fluent\Organization[] $organizations */
$organizations = (new Fluent\Organizations($api))->get();
/** @var Fluent\Organization $organization */
$organization = $organizations[0];
/** @var Fluent\Pipeline $pipelines */
$pipelines = $organization->getPipelines();
/** @var Fluent\Pipeline $pipeline */
$pipeline = $pipelines[0];
/** @var Fluent\Build[] $builds */
$builds = $pipeline->getBuilds();
/** @var Fluent\Build $build */
$build = $builds[0];
/** @var Fluent\Job[] $jobs */
$jobs = $build->getJobs();
/** @var Fluent\Emoji[] $emojis */
$emojis = $organizations[0]->getEmojis();
/** @var Fluent\Agent[] $emojis */
$agents = $organizations[0]->getAgents();
use bbaga\BuildkiteApi\Api\GuzzleClient;
use bbaga\BuildkiteApi\Api\Rest\Fluent;
use bbaga\BuildkiteApi\Api\RestApi;
$client = new GuzzleClient();
$api = new RestApi($client, 'MY_BUILDKITE_API_TOKEN');
/**
* Builds are identified by the follwoing three values
*/
$organizationSlug = 'my-org';
$pipelineSlug = 'my-pipeline';
$buildNumber = 23;
$organization = new Fluent\Organization($api, ['slug' => $organizationSlug]);
$pipeline = new Fluent\Pipeline($api, $organization, ['slug' => $pipelineSlug]);
$build = new Fluent\Build($api, $organization, ['number' => $buildNumber, 'pipeline' => $pipeline]);
$build->fetch()->getJobs();
use bbaga\BuildkiteApi\Api\GuzzleClient;
use bbaga\BuildkiteApi\Api\Rest\Fluent;
use bbaga\BuildkiteApi\Api\RestApi;
$client = new GuzzleClient();
$api = new RestApi($client, 'MY_BUILDKITE_API_TOKEN');
$organization = new Fluent\Organization($api, ['slug' => 'my-org']);
$pipeline = $organization->createPipeline(
[
'name' => 'my-pipeline',
'repository' => '[email protected]:some/repo.git',
'steps' => [
[
'type' => 'script',
'name' => 'upload artifact',
'command' => 'echo "Hello" > artifact.txt \
&& buildkite-agent artifact upload artifact.txt \
&& cat artifact.txt | buildkite-agent annotate --style "success" --context "junit"',
],
[
'type' => 'manual',
'name' => 'Needs to be unblocked',
'command' => 'echo "Unblocked!"',
],
]
]
);
/**
* Pipeline is ready, we can kick off the first build
*/
$buildSettings = [
'commit' => 'HEAD',
'branch' => 'master',
'message' => 'Testing all the things :rocket:',
];
$pipeline->createBuild($buildSettings);