Last active
August 29, 2015 14:03
-
-
Save calclavia/8020eb19b16dc5b5eae5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generates a TeamCity XML changelog via the REST API. | |
*/ | |
task("createChangelog").doLast { | |
def teamCityURL = "http://ci.calclavia.com/" | |
/** | |
* Create a new file | |
*/ | |
def file = new FileOutputStream("output/changelog.xml") | |
def out = new BufferedOutputStream(file) | |
/** | |
* Grab the build first, parse the XML to find the changelog XML URL | |
*/ | |
def changesXML = new XmlSlurper().parse(teamCityURL + "guestAuth/app/rest/changes?locator=build:(id:" + teamcity["teamcity.build.id"] + ")") | |
def changes = changesXML.change | |
/** | |
* Add the XML definition header in the front of the file and remove all other occurrences of the XML header | |
*/ | |
out << ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><changes>") | |
println("createChangelog: Identified " + changes.size() + " changes to be written into the changelog.") | |
for (int i = 0; i < changes.size(); i++) { | |
/** | |
* Write each changelog XML into the URL | |
*/ | |
def changelogURL = teamCityURL + "guestAuth/app/rest/changes/id:" + changes[i][email protected]() | |
out << new URL(changelogURL).getText().replaceAll("<\\?xml version=\"1\\.0\" encoding=\"UTF-8\" standalone=\"yes\"\\?>", "") | |
} | |
out << "</changes>" | |
out.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment