Skip to content

Commit d7452f0

Browse files
Added support for triggering a pipeline (#612)
Co-authored-by: Graham Campbell <[email protected]>
1 parent cb5b726 commit d7452f0

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [11.1.0] - UPCOMING
99

1010
* Added CI schedule variables endpoints
11+
* Added support for triggering a pipeline
1112

1213
[11.1.0]: https://github.com/GitLabPHP/Client/compare/11.0.0...11.1.0
1314

src/Api/Projects.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,23 @@ public function createTrigger($project_id, string $description)
231231
]);
232232
}
233233

234+
/**
235+
* @param int|string $project_id
236+
* @param string $ref
237+
* @param string $token
238+
* @param array $variables
239+
*
240+
* @return mixed
241+
*/
242+
public function triggerPipeline($project_id, string $ref, string $token, array $variables = [])
243+
{
244+
return $this->post($this->getProjectPath($project_id, 'trigger/pipeline'), [
245+
'ref' => $ref,
246+
'token' => $token,
247+
'variables' => $variables,
248+
]);
249+
}
250+
234251
/**
235252
* @param int|string $project_id
236253
* @param array $parameters {

tests/Api/ProjectsTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,30 @@ public function shouldCreateTrigger(): void
569569
$this->assertEquals($expectedArray, $api->createTrigger(1, 'foobar'));
570570
}
571571

572+
/**
573+
* @test
574+
*/
575+
public function shouldTriggerPipeline(): void
576+
{
577+
$expectedArray = [
578+
'id' => 4,
579+
'sha' => 'commit_hash',
580+
'ref' => 'master',
581+
'status' => 'pending',
582+
];
583+
584+
$api = $this->getApiMock();
585+
$api->expects($this->once())
586+
->method('post')
587+
->with(
588+
'projects/1/trigger/pipeline',
589+
['ref' => 'master', 'token' => 'some_token', 'variables' => ['VAR_1' => 'value 1']]
590+
)
591+
->will($this->returnValue($expectedArray));
592+
593+
$this->assertEquals($expectedArray, $api->triggerPipeline(1, 'master', 'some_token', ['VAR_1' => 'value 1']));
594+
}
595+
572596
/**
573597
* @test
574598
*/

0 commit comments

Comments
 (0)