diff --git a/src/Jenkins.php b/src/Jenkins.php index 2d7ede2..90e9446 100755 --- a/src/Jenkins.php +++ b/src/Jenkins.php @@ -344,11 +344,11 @@ public function getJob(string $jobName): Job * @param string $jobName * @param string $tree * - * @return Job + * @return DataObject */ - public function getJobParams(string $jobName, string $tree = ''): Job + public function getJobParams(string $jobName, string $tree = ''): DataObject { - $tree = $tree ?: 'property[parameterDefinitions[description,name,type,choices]]'; + $tree = $tree ?: 'property[parameterDefinitions[description,name,type,choices,defaultParameterValue]]'; $url = $this->buildUrl('/job/%s/api/json?tree=%s', $jobName, $tree); $cli = $this->getHttpClient()->get($url); @@ -356,9 +356,14 @@ public function getJobParams(string $jobName, string $tree = ''): Job throw new RuntimeException(sprintf('Error on get information for job %s', $jobName)); } - $infos = $cli->getDataObject(); + $data = $cli->getArrayData(); - return new Jenkins\Job($infos, $this); + $params = []; + if (isset($data['property'])) { + $params = Job::fmtBuildParams($data['property']); + } + + return DataObject::new($params); } /** diff --git a/src/Jenkins/Job.php b/src/Jenkins/Job.php index 3b9ba90..1949cce 100755 --- a/src/Jenkins/Job.php +++ b/src/Jenkins/Job.php @@ -37,8 +37,8 @@ class Job */ public function __construct(DataObject $job, Jenkins $jenkins) { - $this->job = $job; - $this->jenkins = $jenkins; + $this->job = $job; + $this->jenkins = $jenkins; } /** @@ -76,17 +76,27 @@ public function getName(): string * @return array */ public function getParametersDefinitions(): array + { + return self::fmtBuildParams($this->job->property); + } + + /** + * @param array $jobProperty + * + * @return array + */ + public static function fmtBuildParams(array $jobProperty): array { $parameters = []; - foreach ($this->job->property as $action) { + foreach ($jobProperty as $action) { if (!isset($action['parameterDefinitions'])) { continue; } foreach ($action['parameterDefinitions'] as $paramDefinition) { $description = $paramDefinition['description'] ?? null; - $paramType = $paramDefinition['type'] ?? null; + $paramType = $paramDefinition['type'] ?? null; $default = $paramDefinition['defaultParameterValue']['value'] ?? null; $choices = $paramDefinition['choices'] ?? null;