1
0
Fork 0
Teamcity-Phabricator-Plugin/Harbormaster-Teamcity-Plugin/TeamCityXmlBuildBuilder.php
Steven Cooney 82aa3d1405 Update Harbormaster Defined Parameter Names
We were previously setting the phabricator variabels we needs within builds to be environment variables however there are issues arount pulling out ENVS when on the agent within `buildStarted` step. To resolve the lack of environment variable access we are going to use sharedParameters which also doesn't work with variables prefixed with `env.` hence the rename.
2019-06-03 17:10:39 +01:00

80 lines
No EOL
2.1 KiB
PHP

<?php
final class TeamCityXmlBuildBuilder {
private $xml;
private $root;
function __construct(){
$this->xml = new DOMDocument('1.0', 'UTF-8');
$this->root = $this->xml->createElement('build');
}
function addBuildId($buildId){
$buildIdElement =
$this->
xml->
createElement('buildType');
$buildIdElement->setAttribute('id', $buildId);
$this->root->appendChild($buildIdElement);
return $this;
}
function addPhabBuildId($buildId){
$this->addProperty("phabricator.BUILD_ID", $buildId);
return $this;
}
function addRevisionId($revisionId){
$this->addProperty("phabricator.REVISION_ID", $revisionId);
return $this;
}
function addBranchName($branchName){
// $this->
// root->
// setAttribute('branchName', $branchName);
$this->addProperty("phabricator.BRANCH_NAME", $branchName);
return $this;
}
function addHarbormasterPHID($phid){
$this->addProperty('phabricator.HARBORMASTER_TARGET_PHID', $phid);
return $this;
}
function addDiffId($diffId){
$this->addProperty('phabricator.DIFF_ID', $diffId);
return $this;
}
function build(){
$this->xml->appendChild($this->root);
return $this->xml->saveXML();
}
private function addProperty($name, $value){
$this->verifyPropertiesExist();
$property = $this->xml->createElement('property');
$property->setAttribute('name', $name);
$property->setAttribute('value', $value);
$this->
root->
getElementsByTagName('properties')->
item(0)->
appendChild($property);
}
private function verifyPropertiesExist(){
if($this->root->getElementsByTagName('properties')->length == 0){
$propertiesElement = $this->xml->createElement('properties');
$this->root->appendChild($propertiesElement);
}
}
}