Forked from calclavia/TeamCity Gradle Changelog.gradle
Last active
October 25, 2017 08:47
-
-
Save AbrarSyed/dd333c2585ad056912e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 + "httpAuth/app/rest/changes/id:" + changes[i][email protected]() | |
out << get(new URL(changelogURL), "username", "pass").replaceAll("<\\?xml version=\"1\\.0\" encoding=\"UTF-8\" standalone=\"yes\"\\?>", "") | |
} | |
out << "</changes>" | |
out.close() | |
} | |
String get(URL url, String username, String pass) { | |
dev connect = url.openConnection() | |
connect.setRequestProperty("Authorization", "Basic "+ (username + ":" + pass).bytes.encodeBase64().toString()) | |
def stream = connect.getInputStream() | |
def out = stream.getText(); | |
stream.close(); | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment