Skip to content

Instantly share code, notes, and snippets.

@toshihirock
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toshihirock/f4a0c96bc4809152d990 to your computer and use it in GitHub Desktop.
Save toshihirock/f4a0c96bc4809152d990 to your computer and use it in GitHub Desktop.
JenkinsのコミットメッセージをGradleで取得する
// 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