public function testUpdate() { $mock = new MockServer(); $mock->queueResponse($this->getTestData(__FUNCTION__)); $apiObject = new Job(new Jenkins($mock), "blat"); $apiObject->color = "fuschia"; $this->assertEquals("fuschia", $apiObject->color); $apiObject->update(); $this->assertEquals("blue", $apiObject->color); }
/** * Constructs an array of jobs from data, which is assumed to be an array of data that * would have come from a Jenkins API call * * @param Jenkins $conn * @param array $data * @return array[\mogman1\Jenkins\Job] */ public static function multiFactory(Jenkins $conn, array $data) { $jobs = array(); foreach ($data as $jobData) { $jobs[] = Job::factory($conn, new JsonData($jobData)); } return $jobs; }
public function testTriggerBuildThrowsExceptionOnBadResponses() { $this->mockServer->queueResponse("HTTP/1.1 404 Not Found\r\n\r\n"); $job = new Job($this->jenkins, "jenkins-web-api"); try { $queueItem = $job->triggerBuild(); $this->fail("No JenkinsConnectionException thrown on invalid build trigger"); } catch (JenkinsConnectionException $e) { $this->assertEquals("Error triggering job build for jenkins-web-api", $e->getMessage()); } $this->mockServer->queueResponse("HTTP/1.1 201 Created\r\nLocation: http://jenkins/queue/item/9\r\n\r\n"); $this->mockServer->queueResponse("HTTP/1.1 404 Not Found\r\n\r\n"); try { $queueItem = $job->triggerBuild(); $this->fail("No JenkinsConnectionException thrown on failure to fetch QueueItem"); } catch (JenkinsConnectionException $e) { $this->assertEquals("Error fetching queue item for triggered job [jenkins-web-api] /queue/item/9", $e->getMessage()); } }
public static function getUrlFromJobNameAndNumber($jobName, $number) { return Job::getUrlFromName($jobName) . "/{$number}"; }
public function getJob($name) { return Job::factory($this, $this->get(Job::getUrlFromName($name))->getJson()); }
protected function updateImpProperties(JsonData $data) { //id and url are not updated since, once they are set, they should never change //TODO: figure out what actions are $this->actions = $data->get('actions', array()); $this->blocked = $data->get('blocked', FALSE); $this->buildable = $data->get('buildable', FALSE); $this->cancelled = $data->get('cancelled', FALSE); $this->inQueueSince = $data->get('inQueueSince', "0"); $this->params = $this->parseParamsString($data->get('params', "")); $this->stuck = $data->get('stuck', FALSE); $this->timestamp = $data->get('timestamp', "0"); $this->why = $data->get('why', ""); $task = $data->get('task', array()); $this->task = $task ? Job::factory($this->conn, new JsonData($data->get('task', array()))) : NULL; $build = $data->get('executable', array()); $this->executable = $build ? Build::factory($this->conn, $this->task->name, new JsonData($build)) : NULL; }
protected function updateImpProperties(JsonData $data) { $this->assignedLabels = $data->get('assignedLabels', array()); $this->description = $data->get('description'); $this->jobs = Job::multiFactory($this->conn, $data->get('jobs', array())); $this->mode = $data->get('mode', "UNKNOWN"); $this->nodeDescription = $data->get('nodeDescription'); $this->nodeName = $data->get('nodeName'); $this->numExecutors = $data->get('numExecutors', 0); $this->overallLoad = $data->get('overallLoad', array()); $this->quietingDown = $data->get('quietingDown', FALSE); $this->slaveAgentPort = $data->get('slaveAgentPort', 0); $this->unlabeledLoad = $data->get('unlabeledLoad', array()); $this->useCrumbs = $data->get('useCrumbs', FALSE); $this->useSecurity = $data->get('useSecurity', FALSE); $this->views = View::multiFactory($this->conn, $data->get('views', array())); $viewData = $data->get('primaryView', array()); $this->primaryView = $viewData ? View::factory($this->conn, new JsonData($data->get('primaryView', array()))) : NULL; }