Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit d5b8881

Browse files
Christopher ChewChristopher Chew
authored andcommitted
Added a 'describe' action for the jenkins script.
1 parent 83e6e52 commit d5b8881

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/scripts/jenkins.coffee

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# hubot jenkins build <job> - builds the specified Jenkins job
1313
# hubot jenkins build <job>, <params> - builds the specified Jenkins job with parameters as key=value&key2=value2
1414
# hubot jenkins list - lists Jenkins jobs
15+
# hubot jenkins describe <job> - Describes the specified Jenkins job
16+
1517
#
1618
# Author:
1719
# dougcole
@@ -40,6 +42,50 @@ jenkinsBuild = (msg) ->
4042
else
4143
msg.send "Jenkins says: #{body}"
4244

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+
response += "DESCRIPTION: #{content.description}\n"
67+
response += "ENABLED: #{content.buildable}\n"
68+
response += "STATUS: #{content.color}\n"
69+
tmpReport = ""
70+
for report in content.healthReport
71+
tmpReport += "\n #{report.description}"
72+
response += "HEALTH: #{tmpReport}\n"
73+
74+
parameters = ""
75+
for item in content.actions
76+
if item.parameterDefinitions
77+
for param in item.parameterDefinitions
78+
tmpDescription = if param.description then " - #{param.description} " else ""
79+
tmpDefault = if param.defaultParameterValue then " (default=#{param.defaultParameterValue.value})" else ""
80+
parameters += "\n #{param.name}#{tmpDescription}#{tmpDefault}"
81+
82+
if parameters != ""
83+
response += "PARAMETERS: #{parameters}\n"
84+
85+
msg.send response
86+
catch error
87+
msg.send error
88+
4389
jenkinsList = (msg) ->
4490
url = process.env.HUBOT_JENKINS_URL
4591
job = msg.match[1]
@@ -70,6 +116,9 @@ module.exports = (robot) ->
70116
robot.respond /jenkins list/i, (msg) ->
71117
jenkinsList(msg)
72118

119+
robot.respond /jenkins describe ([\w\.\-_]+)/i, (msg) ->
120+
jenkinsDescribe(msg)
121+
73122
robot.jenkins = {
74123
list: jenkinsList,
75124
build: jenkinsBuild

0 commit comments

Comments
 (0)