Last active
August 29, 2015 14:10
-
-
Save toshihirock/f4a0c96bc4809152d990 to your computer and use it in GitHub Desktop.
JenkinsのコミットメッセージをGradleで取得する
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
// something | |
// jenkins | |
import groovy.json.* | |
ext { | |
jenkinsUrl = 'http://localhost:8080' | |
buildNumber = System.getenv("BUILD_NUMBER"); | |
jobName = System.getenv("JOB_NAME"); | |
println "build number is ${buildNumber}" | |
println "jobName is ${jobName}" | |
} | |
def getJson(url) { | |
println "start getJson $url" | |
def response = new URL(url).text | |
return new JsonSlurper().parseText(response) | |
} | |
def getJenkinsMessage(message) { | |
def url = "${jenkinsUrl}/job/${jobName}/${buildNumber}/api/json" | |
def items = getJson(url)['changeSet']['items'] | |
items.eachWithIndex() { obj, i -> | |
message += obj['msg'] + ' ' | |
} | |
return message | |
} | |
task jenkins << { | |
String message = "B${buildNumber} " | |
println getJenkinsMessage(message) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment