Skip to content

Commit d1bc7a9

Browse files
hrobertsonm1guelpf
authored andcommitted
Add creating pipelines with variables
1 parent d18ae7a commit d1bc7a9

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

lib/Gitlab/Api/Projects.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,26 @@ public function pipeline($project_id, $pipeline_id)
235235
/**
236236
* @param int $project_id
237237
* @param string $commit_ref
238+
* @param array $variables (
239+
* @var array (
240+
* @var string $key The name of the variable
241+
* @var mixed $value The value of the variable
242+
* @var string $variable_type env_var (default) or file
243+
* )
244+
* )
238245
* @return mixed
239246
*/
240-
public function createPipeline($project_id, $commit_ref)
247+
public function createPipeline($project_id, $commit_ref, $variables = null)
241248
{
242-
return $this->post($this->getProjectPath($project_id, 'pipeline'), array(
243-
'ref' => $commit_ref));
249+
$parameters = array(
250+
'ref' => $commit_ref,
251+
);
252+
253+
if ($variables !== null) {
254+
$parameters['variables'] = $variables;
255+
}
256+
257+
return $this->post($this->getProjectPath($project_id, 'pipeline'), $parameters);
244258
}
245259

246260
/**

test/Gitlab/Tests/Api/ProjectsTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,35 @@ public function shouldCreatePipeline()
567567
$this->assertEquals($expectedArray, $api->createPipeline(1, 'test-pipeline'));
568568
}
569569

570+
/**
571+
* @test
572+
*/
573+
public function shouldCreatePipelineWithVariables()
574+
{
575+
$expectedArray = array(
576+
array('id' => 4, 'status' => 'created', 'ref' => 'test-pipeline')
577+
);
578+
$variables = array(
579+
array(
580+
'key' => 'test_var_1',
581+
'value' => 'test_value_1'
582+
),
583+
array(
584+
'key' => 'test_var_2',
585+
'variable_type' => 'file',
586+
'value' => 'test_value_2'
587+
)
588+
);
589+
590+
$api = $this->getApiMock();
591+
$api->expects($this->once())
592+
->method('post')
593+
->with('projects/1/pipeline', array('ref' => 'test-pipeline', 'variables' => $variables))
594+
->will($this->returnValue($expectedArray));
595+
596+
$this->assertEquals($expectedArray, $api->createPipeline(1, 'test-pipeline', $variables));
597+
}
598+
570599
/**
571600
* @test
572601
*/

0 commit comments

Comments
 (0)