diff --git a/src/Api/Jobs.php b/src/Api/Jobs.php index bd318f89..e21f1c3b 100644 --- a/src/Api/Jobs.php +++ b/src/Api/Jobs.php @@ -240,12 +240,16 @@ public function keepArtifacts($project_id, int $job_id) /** * @param int|string $project_id * @param int $job_id + * @param array $parameters * * @return mixed */ - public function play($project_id, int $job_id) + public function play($project_id, int $job_id, array $parameters = []) { - return $this->post('projects/'.self::encodePath($project_id).'/jobs/'.self::encodePath($job_id).'/play'); + $resolver = new OptionsResolver(); + $resolver->setDefined('job_variables_attributes'); + + return $this->post('projects/'.self::encodePath($project_id).'/jobs/'.self::encodePath($job_id).'/play', $resolver->resolve($parameters)); } /** diff --git a/tests/Api/JobsTest.php b/tests/Api/JobsTest.php index 9ca55526..3a0c165f 100644 --- a/tests/Api/JobsTest.php +++ b/tests/Api/JobsTest.php @@ -298,6 +298,36 @@ public function shouldPlay(): void $this->assertEquals($expectedArray, $api->play(1, 3)); } + /** + * @test + */ + public function shouldPlayWithVariables(): void + { + $expectedArray = ['id' => 3, 'name' => 'A job']; + + $jobVariables = [ + 'job_variables_attributes' => [ + [ + 'key' => 'TEST_VAR_1', + 'value' => 'test1', + ], + [ + 'key' => 'TEST_VAR_2', + 'value' => 'test2', + ], + ], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/jobs/3/play', $jobVariables) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->play(1, 3, $jobVariables)); + } + protected function getApiClass() { return Jobs::class;