Skip to content

Instantly share code, notes, and snippets.

@calclavia
Last active August 29, 2015 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save calclavia/8020eb19b16dc5b5eae5 to your computer and use it in GitHub Desktop.
Save calclavia/8020eb19b16dc5b5eae5 to your computer and use it in GitHub Desktop.
/**
* 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].@id.text()
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