|
12 | 12 | # hubot jenkins build <job> - builds the specified Jenkins job
|
13 | 13 | # hubot jenkins build <job>, <params> - builds the specified Jenkins job with parameters as key=value&key2=value2
|
14 | 14 | # hubot jenkins list - lists Jenkins jobs
|
| 15 | +# hubot jenkins describe <job> - Describes the specified Jenkins job |
| 16 | + |
15 | 17 | #
|
16 | 18 | # Author:
|
17 | 19 | # dougcole
|
@@ -40,6 +42,57 @@ jenkinsBuild = (msg) ->
|
40 | 42 | else
|
41 | 43 | msg.send "Jenkins says: #{body}"
|
42 | 44 |
|
| 45 | +jenkinsDescribe = (msg) -> |
| 46 | + url = process.env.HUBOT_JENKINS_URL |
| 47 | + job = msg.match[1] |
| 48 | + |
| 49 | + path = "#{url}/job/#{job}/api/json" |
| 50 | + |
| 51 | + req = msg.http(path) |
| 52 | + |
| 53 | + if process.env.HUBOT_JENKINS_AUTH |
| 54 | + auth = new Buffer(process.env.HUBOT_JENKINS_AUTH).toString('base64') |
| 55 | + req.headers Authorization: "Basic #{auth}" |
| 56 | + |
| 57 | + req.header('Content-Length', 0) |
| 58 | + req.get() (err, res, body) -> |
| 59 | + if err |
| 60 | + msg.send "Jenkins says: #{err}" |
| 61 | + else |
| 62 | + response = "" |
| 63 | + try |
| 64 | + content = JSON.parse(body) |
| 65 | + response += "JOB: #{content.displayName}\n" |
| 66 | + |
| 67 | + if content.description |
| 68 | + response += "DESCRIPTION: #{content.description}\n" |
| 69 | + |
| 70 | + response += "ENABLED: #{content.buildable}\n" |
| 71 | + response += "STATUS: #{content.color}\n" |
| 72 | + |
| 73 | + tmpReport = "" |
| 74 | + if content.healthReport.length > 0 |
| 75 | + for report in content.healthReport |
| 76 | + tmpReport += "\n #{report.description}" |
| 77 | + else |
| 78 | + tmpReport = " unknown" |
| 79 | + response += "HEALTH: #{tmpReport}\n" |
| 80 | + |
| 81 | + parameters = "" |
| 82 | + for item in content.actions |
| 83 | + if item.parameterDefinitions |
| 84 | + for param in item.parameterDefinitions |
| 85 | + tmpDescription = if param.description then " - #{param.description} " else "" |
| 86 | + tmpDefault = if param.defaultParameterValue then " (default=#{param.defaultParameterValue.value})" else "" |
| 87 | + parameters += "\n #{param.name}#{tmpDescription}#{tmpDefault}" |
| 88 | + |
| 89 | + if parameters != "" |
| 90 | + response += "PARAMETERS: #{parameters}\n" |
| 91 | + |
| 92 | + msg.send response |
| 93 | + catch error |
| 94 | + msg.send error |
| 95 | + |
43 | 96 | jenkinsList = (msg) ->
|
44 | 97 | url = process.env.HUBOT_JENKINS_URL
|
45 | 98 | job = msg.match[1]
|
@@ -70,6 +123,9 @@ module.exports = (robot) ->
|
70 | 123 | robot.respond /jenkins list/i, (msg) ->
|
71 | 124 | jenkinsList(msg)
|
72 | 125 |
|
| 126 | + robot.respond /jenkins describe ([\w\.\-_]+)/i, (msg) -> |
| 127 | + jenkinsDescribe(msg) |
| 128 | + |
73 | 129 | robot.jenkins = {
|
74 | 130 | list: jenkinsList,
|
75 | 131 | build: jenkinsBuild
|
|
0 commit comments