Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ Launch a Job
// bool(true) if successful or throws a RuntimeException
```

Launch a Job with Parameters
------------

```php
$job = $jenkins->launchJob("clone-deploy",array(
'name'=> <param_name>, 'value'=> <param_value>
'name'=> <param2_name>, 'value'=> <param2_value>
)
);
var_dump($job);
// bool(true) if successful or throws a RuntimeException
```

List the jobs of a given view
-----------------------------
Expand Down
14 changes: 9 additions & 5 deletions src/Jenkins.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,15 @@ public function getExecutors($computer = '(master)')
*/
public function launchJob($jobName, $parameters = array())
{
if (0 === count($parameters)) {
$url = sprintf('%s/job/%s/build', $this->baseUrl, $jobName);
} else {
$url = sprintf('%s/job/%s/buildWithParameters', $this->baseUrl, $jobName);
$url = sprintf('%s/job/%s/build', $this->baseUrl, $jobName);

if ($parameters) {
$parameters = array(
'json' => json_encode(array(
"parameter" => $parameters
)
)
);
}

$curl = curl_init($url);
Expand All @@ -259,7 +264,6 @@ public function launchJob($jobName, $parameters = array())
}

curl_setopt($curl, \CURLOPT_HTTPHEADER, $headers);

curl_exec($curl);

$this->validateCurl($curl, sprintf('Error trying to launch job "%s" (%s)', $jobName, $url));
Expand Down