1
0
Fork 0
Teamcity-Phabricator-Plugin/Harbormaster-Teamcity-Plugin/TeamCityXmlBuildBuilder.php
Steven Cooney cefb59b73a Remove BRANCH_NAME Parameter
In the past TeamCity allowed us to spoof the branch we ran a build configuration on. We were going to utilise this with each differential revision having its own TeamCity branch. However in a recent change (post 2018.2.2) branches specified in builds must have a corresponding VCS branch otherwise the build is marked as failed. We therefore don't need a branch name within the teamcity plugin.

We are still passing through the REVISION_BUILD to allow us to display the snapshot within TeamCity.
2019-06-05 11:22:53 +01:00

77 lines
No EOL
2 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 addRevisionBuild($revisionBuild){
$this->addProperty("phabricator.REVISION_BUILD", $revisionBuild);
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);
}
}
}