composer require bbaga/buildkite-php PsrHttpClientClientInterface 구현은 bbaga/buildkite-php-guzzle-client 패키지에서 사용할 수 있습니다.
use bbaga BuildkiteApi Api RestApi ;
/** @var PsrHttpClientClientInterface $client */
$ client = new MyHttpClient ();
$ api = new RestApi ( $ client , ' MY_BUILDKITE_API_TOKEN ' ); use bbaga BuildkiteApi Api GraphQLApi ;
/** @var PsrHttpClientClientInterface $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 FluentOrganization[] $organizations */
$ organizations = ( new Fluent Organizations ( $ api ))-> get ();
/** @var FluentOrganization $organization */
$ organization = $ organizations [ 0 ];
/** @var FluentPipeline $pipelines */
$ pipelines = $ organization -> getPipelines ();
/** @var FluentPipeline $pipeline */
$ pipeline = $ pipelines [ 0 ];
/** @var FluentBuild[] $builds */
$ builds = $ pipeline -> getBuilds ();
/** @var FluentBuild $build */
$ build = $ builds [ 0 ];
/** @var FluentJob[] $jobs */
$ jobs = $ build -> getJobs ();
/** @var FluentEmoji[] $emojis */
$ emojis = $ organizations [ 0 ]-> getEmojis ();
/** @var FluentAgent[] $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 ); 조직 관련 방법은 $api->organization() 을 통해 노출됩니다.
조직 API에 대한 자세한 문서는 여기에서 확인할 수 있습니다
$ api -> organization ()-> list (); $ api -> organization ()-> get ( ' my-organization ' ); 파이프 라인 관련 방법은 $api->pipeline()
파이프 라인 API에 대한 자세한 문서는 여기에서 확인할 수 있습니다
$ api -> pipeline ()-> list ( ' my-organizations ' ); $ api -> pipeline ()-> get ( ' my-organization ' , ' my-pipeline ' ); $ pipelineData = [
' name ' => ' My Pipeline ' ,
' repository ' => ' [email protected]:acme-inc/my-pipeline.git ' ,
' steps ' => [
[
' type ' => ' script ' ,
' name ' => ' Build :package: ' ,
' command ' => ' script/release.sh ' ,
],
],
];
$ api -> pipeline ()-> create ( ' my-organization ' , $ pipelineData ); $ pipelineData = [
' repository ' => ' [email protected]:acme-inc/new-repo.git ' ,
];
$ api -> pipeline ()-> update ( ' my-organization ' , ' my-pipelines ' , $ pipelineData ); $ api -> pipeline ()-> delete ( ' my-organization ' , ' my-pipeline ' ); 빌드 관련 방법은 $api->build() 를 통해 노출됩니다.
빌드 API에 대한 자세한 문서는 여기에서 확인할 수 있습니다
$ api -> build ()-> listAll ( $ queryParameters ); $ buildNumber = 1 ;
$ api -> build ()-> get ( ' my-organization ' , ' my-pipeline ' , $ buildNumber ); $ api -> build ()-> getByOrganization ( ' my-organization ' , $ queryParameters ); $ api -> build ()-> getByPipeline ( ' my-organization ' , ' my-pipeline ' , $ queryParameters ); $ buildSettings = [
' commit ' => ' abcd0b72a1e580e90712cdd9eb26d3fb41cd09c8 ' ,
' branch ' => ' master ' ,
' message ' => ' Testing all the things :rocket: ' ,
' author ' => [
' name ' => ' Keith Pitt ' ,
' email ' => ' [email protected] ' ,
],
' env ' => [
' MY_ENV_VAR ' => ' some_value ' ,
],
' meta_data ' => [
' some build data ' => ' value ' ,
' other build data ' => true ,
],
];
$ api -> build ()-> create ( ' my-organization ' , ' my-pipeline ' , $ buildSettings ); $ buildNumber = 12 ;
$ api -> build ()-> cancel ( ' my-organization ' , ' my-pipeline ' , $ buildNumber ); $ buildNumber = 12 ;
$ api -> build ()-> rebuild ( ' my-organization ' , ' my-pipeline ' , $ buildNumber ); 작업 관련 방법은 $api->job() 를 통해 노출됩니다.
Jobs API에 대한 자세한 문서는 여기에서 확인할 수 있습니다
$ buildNumber = 12 ;
$ jobId = ' 0738da5f-0372-4b02-a1cb-f07a12fbcdcd ' ;
$ api -> job ()-> retry ( ' my-organization ' , ' my-pipeline ' , $ buildNumber , $ jobId ); $ buildNumber = 12 ;
$ jobId = ' 0738da5f-0372-4b02-a1cb-f07a12fbcdcd ' ;
$ api -> job ()-> unblock ( ' my-organization ' , ' my-pipeline ' , $ buildNumber , $ jobId ); $ buildNumber = 12 ;
$ jobId = ' 0738da5f-0372-4b02-a1cb-f07a12fbcdcd ' ;
$ api -> job ()-> getLogOutput ( ' my-organization ' , ' my-pipeline ' , $ buildNumber , $ jobId ); $ buildNumber = 12 ;
$ jobId = ' 0738da5f-0372-4b02-a1cb-f07a12fbcdcd ' ;
$ api -> job ()-> deleteLogOutput ( ' my-organization ' , ' my-pipeline ' , $ buildNumber , $ jobId ); $ buildNumber = 12 ;
$ jobId = ' 0738da5f-0372-4b02-a1cb-f07a12fbcdcd ' ;
$ api -> job ()-> getEnvironmentVariables ( ' my-organization ' , ' my-pipeline ' , $ buildNumber , $ jobId ); 작업 관련 방법은 $api->artifact() 를 통해 노출됩니다.
아티팩트 API에 대한 자세한 문서는 여기에서 확인할 수 있습니다
$ buildNumber = 12 ;
$ api -> artifact ()-> getByBuild ( ' my-organization ' , ' my-pipeline ' , $ buildNumber ); $ buildNumber = 12 ;
$ jobId = ' 0738da5f-0372-4b02-a1cb-f07a12fbcdcd ' ;
$ api -> artifact ()-> getByJob ( ' my-organization ' , ' my-pipeline ' , $ buildNumber , $ jobId ); $ buildNumber = 12 ;
$ jobId = ' 0738da5f-0372-4b02-a1cb-f07a12fbcdcd ' ;
$ artifactId = ' 567038da5f03724b02a1cbf07a12fbcedfg ' ;
$ api -> artifact ()-> get (
' my-organization ' ,
' my-pipeline ' ,
$ buildNumber ,
$ jobId ,
$ artifactId
); $ buildNumber = 12 ;
$ jobId = ' 0738da5f-0372-4b02-a1cb-f07a12fbcdcd ' ;
$ artifactId = ' 567038da5f03724b02a1cbf07a12fbcedfg ' ;
$ api -> artifact ()-> delete (
' my-organization ' ,
' my-pipeline ' ,
$ buildNumber ,
$ jobId ,
$ artifactId
); 에이전트 관련 방법은 $api->agent() 통해 노출됩니다.
에이전트 API에 대한 자세한 문서는 여기에서 확인할 수 있습니다
$ api -> agent ()-> list ( ' my-organization ' ); $ agentId = ' 1d633306-de28-4944-ad84-fde0d50a6c9e ' ;
$ api -> agent ()-> list ( ' my-organization ' , $ agentId ); $ agentId = ' 1d633306-de28-4944-ad84-fde0d50a6c9e ' ;
$ api -> agent ()-> list ( ' my-organization ' , $ agentId ); 주석 관련 방법은 $api->annotation() 을 통해 노출됩니다.
주석 API에 대한 자세한 문서는 여기에서 확인할 수 있습니다
$ buildNumber = 12 ;
$ api -> annotation ()-> list ( ' my-organization ' , ' my-pipeline ' , $ buildNumber ); 사용자 관련 방법은 $api->user() 를 통해 노출됩니다.
사용자 API에 대한 자세한 문서는 여기에서 확인할 수 있습니다
$ api -> user ()-> whoami (); 이모티콘 관련 방법은 $api->emoji() 를 통해 노출됩니다.
사용자 API에 대한 자세한 문서는 여기에서 확인할 수 있습니다
$ api -> emoji ()-> list ( ' my-organization ' );make test통합 테스트에는 BuildKite 계정 및 러닝 에이전트가 필요하며 다음 환경 변수를 설정해야합니다.
BK_TEST_TOKENBK_TEST_ORGBK_TEST_PREFIXGITHUB_REFGITHUB_REPOSITORY phpunit.xml.dist 의 사본을 만들고 다음 스 니펫으로 확장하여 phpunit.xml 에서 설정할 수 있습니다.
< php >
< env name = " BK_TEST_TOKEN " value = " my-buildkite-api-token " />
< env name = " BK_TEST_ORG " value = " my-organization-slug " />
< env name = " BK_TEST_PREFIX " value = " something-uniqe " />
< env name = " GITHUB_REF " value = " refs/heads/master " />
< env name = " GITHUB_REPOSITORY " value = " your-name/buildkite-php " />
</ php >환경 변수가 설정되면 테스트 스위트를 시작할 수 있습니다.
make integration